protected function _traverseClause(Query $query, $name = '', $config = [])
    {
        $clause = $query->clause($name);
        if (!$clause || !$clause->count()) {
            return false;
        }

        $alias = $config['hasOneAlias'];
        $fields = $this->_translationFields();
        $mainTableAlias = $config['mainTableAlias'];
        $mainTableFields = $this->_mainFields();
        $joinRequired = false;

        $clause->traverse(function ($expression) use ($fields, $alias, $mainTableAlias, $mainTableFields, &$joinRequired) {
            if (!($expression instanceof FieldInterface)) {
                return;
            }
            $field = $expression->getField();
            if (!is_string($field) || strpos($field, '.')) {
                return;
            }

            if (in_array($field, $fields)) {
                $joinRequired = true;
                $expression->setField("$alias.$field");

                return;
            }

            if (in_array($field, $mainTableFields)) {
                $expression->setField("$mainTableAlias.$field");
            }
        });

        return $joinRequired;
    }
protected function _traverseClause(Query $query, $name = '', $config = [])
    {
        $clause = $query->clause($name);
        if (!$clause || !$clause->count()) {
            return false;
        }

        $alias = $config['hasOneAlias'];
        $fields = $this->_translationFields();
        $mainTableAlias = $config['mainTableAlias'];
        $mainTableFields = $this->_mainFields();
        $joinRequired = false;

        $clause->traverse(function ($expression) use ($fields, $alias, $mainTableAlias, $mainTableFields, &$joinRequired) {
            if (!($expression instanceof FieldInterface)) {
                return;
            }
            $field = $expression->getField();
            if (!is_string($field) || strpos($field, '.')) {
                return;
            }

            if (in_array($field, $fields)) {
                $joinRequired = true;
                $expression->setField("$alias.$field");

                return;
            }

            if (in_array($field, $mainTableFields)) {
                $expression->setField("$mainTableAlias.$field");
            }
        });

        return $joinRequired;
    }
protected function _traverseClause ( Query $ query , $ name = '' , $ config = [ ] ) { $ clause = $ query -> clause ( $ name ) ; if ( ! $ clause || ! $ clause -> count ( ) ) { return false ; } $ alias = $ config [ 'hasOneAlias' ] ; $ fields = $ this -> _translationFields ( ) ; $ mainTableAlias = $ config [ 'mainTableAlias' ] ; $ mainTableFields = $ this -> _mainFields ( ) ; $ joinRequired = false ; $ clause -> traverse ( function ( $ expression ) use ( $ fields , $ alias , $ mainTableAlias , $ mainTableFields , & $ joinRequired ) { if ( ! ( $ expression instanceof FieldInterface ) ) { return ; } $ field = $ expression -> getField ( ) ; if ( ! is_string ( $ field ) || strpos ( $ field , '.' ) ) { return ; } if ( in_array ( $ field , $ fields ) ) { $ joinRequired = true ; $ expression -> setField ( "$alias.$field" ) ; return ; } if ( in_array ( $ field , $ mainTableFields ) ) { $ expression -> setField ( "$mainTableAlias.$field" ) ; } } ) ; return $ joinRequired ; }
Traverse over a clause to alias fields

The objective here is to transparently prevent ambiguous field errors by
prefixing fields with the appropriate table alias. This method currently
expects to receive a where clause only.

@param \Cake\ORM\Query $query the query to check
@param string $name The clause name
@param array $config the config to use for adding fields
@return bool Whether a join to the translation table is required
Traverse over a clause to alias fields