/**
* Creates the associations between the bound table and every field passed to
* this method.
*
* Additionally it creates a `i18n` HasMany association that will be
* used for fetching all versions for each record in the bound table
*
* @param string $table the table name to use for storing each field version
* @return void
*/
public function setupFieldAssociations($table)
{
$alias = $this->_table->alias();
foreach ($this->_fields() as $field) {
$name = $this->_table->alias() . '_' . $field . '_version';
$target = TableRegistry::get($name);
$target->table($table);
$this->_table->hasOne($name, ['targetTable' => $target, 'foreignKey' => 'foreign_key', 'joinType' => 'LEFT', 'conditions' => [$name . '.model' => $alias, $name . '.field' => $field], 'propertyName' => $field . '_version']);
}
$this->_table->hasMany($table, ['foreignKey' => 'foreign_key', 'strategy' => 'subquery', 'conditions' => ["{$table}.model" => $alias], 'propertyName' => '__version', 'dependent' => true]);
}