Cake\ORM\Behavior\TranslateBehavior::setupFieldAssociations PHP Метод

setupFieldAssociations() публичный Метод

Additionally it creates a i18n HasMany association that will be used for fetching all translations for each record in the bound table
public setupFieldAssociations ( array $fields, string $table, string $model, string $strategy ) : void
$fields array list of fields to create associations for
$table string the table name to use for storing each field translation
$model string the model field value
$strategy string the strategy used in the _i18n association
Результат void
    public function setupFieldAssociations($fields, $table, $model, $strategy)
    {
        $targetAlias = $this->_translationTable->alias();
        $alias = $this->_table->alias();
        $filter = $this->_config['onlyTranslated'];
        $tableLocator = $this->tableLocator();
        foreach ($fields as $field) {
            $name = $alias . '_' . $field . '_translation';
            if (!$tableLocator->exists($name)) {
                $fieldTable = $tableLocator->get($name, ['className' => $table, 'alias' => $name, 'table' => $this->_translationTable->table()]);
            } else {
                $fieldTable = $tableLocator->get($name);
            }
            $conditions = [$name . '.model' => $model, $name . '.field' => $field];
            if (!$this->_config['allowEmptyTranslations']) {
                $conditions[$name . '.content !='] = '';
            }
            $this->_table->hasOne($name, ['targetTable' => $fieldTable, 'foreignKey' => 'foreign_key', 'joinType' => $filter ? 'INNER' : 'LEFT', 'conditions' => $conditions, 'propertyName' => $field . '_translation']);
        }
        $conditions = ["{$targetAlias}.model" => $model];
        if (!$this->_config['allowEmptyTranslations']) {
            $conditions["{$targetAlias}.content !="] = '';
        }
        $this->_table->hasMany($targetAlias, ['className' => $table, 'foreignKey' => 'foreign_key', 'strategy' => $strategy, 'conditions' => $conditions, 'propertyName' => '_i18n', 'dependent' => true]);
    }