Skip to content

Commit

Permalink
Merge pull request #7734 from cakephp/fix-translate-empty-fields
Browse files Browse the repository at this point in the history
Fixed problem in translate behavior when all translate fields are clean
  • Loading branch information
markstory committed Nov 25, 2015
2 parents 48db3cc + aa57d64 commit 238b053
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -276,6 +276,11 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o

$values = $entity->extract($this->_config['fields'], true);
$fields = array_keys($values);

if (empty($fields)) {
return;
}

$primaryKey = (array)$this->_table->primaryKey();
$key = $entity->get(current($primaryKey));
$model = $this->_config['referenceName'];
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php
Expand Up @@ -1019,4 +1019,23 @@ public function testEmptyTranslations()
$result = $table->find()->first();
$this->assertNull($result->description);
}

/**
* Test save with clean translate fields
*
* @return void
*/
public function testSaveWithCleanFields()
{
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title']]);
$table->entityClass(__NAMESPACE__ . '\Article');
I18n::locale('fra');
$article = $table->get(1);
$article->set('body', 'New Body');
$table->save($article);
$result = $table->get(1);
$this->assertEquals('New Body', $result->body);
$this->assertSame($article->title, $result->title);
}
}

0 comments on commit 238b053

Please sign in to comment.