Skip to content

Commit

Permalink
not overwritting fields with a null translation
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 27, 2014
1 parent 8db0595 commit 6fe3d92
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Model/Behavior/TranslateBehavior.php
Expand Up @@ -219,7 +219,11 @@ protected function _rowMapper($results, $locale) {
continue;
}

$row->set($field, $translation->get('content'), $options);
$content = $translation->get('content');
if ($content !== null) {
$row->set($field, $content, $options);
}

unset($row[$name]);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -78,6 +78,23 @@ public function testFindSingleLocale() {
$this->assertSame($expected, $results);
}

/**
* Tests that fields from a translated model are not overriden if translation
* is null
*
* @return void
*/
public function testFindSingleLocaleWithNullTranslation() {
$table = TableRegistry::get('Comments');
$table->addBehavior('Translate', ['fields' => ['comment']]);
$table->locale('spa');
$results = $table->find()
->where(['Comments.id' => 6])
->combine('id', 'comment')->toArray();
$expected = [6 => 'Second Comment for Second Article'];
$this->assertSame($expected, $results);
}

/**
* Tests that overriding fields with the translate behavior works when
* using conditions and that all other columns are preserved
Expand Down

0 comments on commit 6fe3d92

Please sign in to comment.