protected function _prepare()
    {
        $table = $this->_context['table'];
        $entity = $this->_context['entity'];
        if (empty($table)) {
            if (is_array($entity) || $entity instanceof Traversable) {
                foreach ($entity as $e) {
                    $entity = $e;
                    break;
                }
            }
            $isEntity = $entity instanceof EntityInterface;

            if ($isEntity) {
                $table = $entity->getSource();
            }
            if (!$table && $isEntity && get_class($entity) !== 'Cake\ORM\Entity') {
                list(, $entityClass) = namespaceSplit(get_class($entity));
                $table = Inflector::pluralize($entityClass);
            }
        }
        if (is_string($table)) {
            $table = $this->getTableLocator()->get($table);
        }

        if (!($table instanceof RepositoryInterface)) {
            throw new RuntimeException(
                'Unable to find table class for current entity'
            );
        }
        $this->_isCollection = (
            is_array($entity) ||
            $entity instanceof Traversable
        );

        $alias = $this->_rootName = $table->getAlias();
        $this->_tables[$alias] = $table;
    }