Skip to content

Commit

Permalink
Dealing with the creation of i18n field tables elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Conroy committed Jan 7, 2015
1 parent b4f6dcf commit 3d32968
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -125,11 +125,15 @@ public function setupFieldAssociations($fields, $table, $model, $strategy)
foreach ($fields as $field) {
$name = $alias . '_' . $field . '_translation';

$fieldTable = TableRegistry::get($name, [
'className' => $table,
'alias' => $name,
'table' => $targetTable->table()
]);
if (!TableRegistry::exists($name)) {
$fieldTable = TableRegistry::get($name, [
'className' => $table,
'alias' => $name,
'table' => $targetTable->table()
]);
} else {
$fieldTable = TableRegistry::get($name);
}

$this->_table->hasOne($name, [
'targetTable' => $fieldTable,
Expand Down Expand Up @@ -361,7 +365,7 @@ protected function _rowMapper($results, $locale)
foreach ($this->_config['fields'] as $field) {
$name = $field . '_translation';
$translation = isset($row[$name]) ? $row[$name] : null;

if ($translation === null || $translation === false) {
unset($row[$name]);
continue;
Expand Down

0 comments on commit 3d32968

Please sign in to comment.