Skip to content

Commit

Permalink
Cloning references to field tables from main I18n
Browse files Browse the repository at this point in the history
This should make any subsequent calls to TableRegistry::get work as expected.
  • Loading branch information
Patrick Conroy committed Jan 7, 2015
1 parent 2bea4c1 commit e0961e7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ORM/Behavior/TranslateBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,23 @@ public function initialize(array $config)
*/
public function setupFieldAssociations($fields, $table, $model, $strategy)
{
$targetTable = TableRegistry::get($table);
$targetAlias = Inflector::slug($table);
$alias = $this->_table->alias();
$filter = $this->_config['onlyTranslated'];

foreach ($fields as $field) {
$name = $alias . '_' . $field . '_translation';

$fieldTable = TableRegistry::set($name, $targetTable);
$this->_table->hasOne($name, [
'className' => $table,
'foreignKey' => 'foreign_key',
'targetTable' => $fieldTable,
'joinType' => $filter ? 'INNER' : 'LEFT',
'conditions' => [
$name . '.model' => $model,
$name . '.field' => $field,
$fieldTable->alias() . '.model' => $model,
$fieldTable->alias() . '.field' => $field,
],
'propertyName' => $field . '_translation'
]);
Expand Down

0 comments on commit e0961e7

Please sign in to comment.