protected function _addFieldsToQuery(Query $query, array $config)
    {
        if ($query->isAutoFieldsEnabled()) {
            return true;
        }

        $select = array_filter($query->clause('select'), function ($field) {
            return is_string($field);
        });

        if (!$select) {
            return true;
        }

        $alias = $config['mainTableAlias'];
        $joinRequired = false;
        foreach ($this->_translationFields() as $field) {
            if (array_intersect($select, [$field, "$alias.$field"])) {
                $joinRequired = true;
                $query->select($query->aliasField($field, $config['hasOneAlias']));
            }
        }

        if ($joinRequired) {
            $query->select($query->aliasField('locale', $config['hasOneAlias']));
        }

        return $joinRequired;
    }
protected function _addFieldsToQuery(Query $query, array $config)
    {
        if ($query->isAutoFieldsEnabled()) {
            return true;
        }

        $select = array_filter($query->clause('select'), function ($field) {
            return is_string($field);
        });

        if (!$select) {
            return true;
        }

        $alias = $config['mainTableAlias'];
        $joinRequired = false;
        foreach ($this->_translationFields() as $field) {
            if (array_intersect($select, [$field, "$alias.$field"])) {
                $joinRequired = true;
                $query->select($query->aliasField($field, $config['hasOneAlias']));
            }
        }

        if ($joinRequired) {
            $query->select($query->aliasField('locale', $config['hasOneAlias']));
        }

        return $joinRequired;
    }
protected function _addFieldsToQuery ( Query $ query , array $ config ) { if ( $ query -> isAutoFieldsEnabled ( ) ) { return true ; } $ select = array_filter ( $ query -> clause ( 'select' ) , function ( $ field ) { return is_string ( $ field ) ; } ) ; if ( ! $ select ) { return true ; } $ alias = $ config [ 'mainTableAlias' ] ; $ joinRequired = false ; foreach ( $ this -> _translationFields ( ) as $ field ) { if ( array_intersect ( $ select , [ $ field , "$alias.$field" ] ) ) { $ joinRequired = true ; $ query -> select ( $ query -> aliasField ( $ field , $ config [ 'hasOneAlias' ] ) ) ; } } if ( $ joinRequired ) { $ query -> select ( $ query -> aliasField ( 'locale' , $ config [ 'hasOneAlias' ] ) ) ; } return $ joinRequired ; }
Add translation fields to query

If the query is using autofields (directly or implicitly) add the
main table's fields to the query first.

Only add translations for fields that are in the main table, always
add the locale field though.

@param \Cake\ORM\Query $query the query to check
@param array $config the config to use for adding fields
@return bool Whether a join to the translation table is required
Add translation fields to query