Skip to content
Permalink
Browse files

Fix issue with Model::saveAssociated() and TranslateBehavior

When combining saveAssociated() with validate=first and
TranslateBehavior. Saving data for multiple locales was not done
correctly.

Fixes #3272
  • Loading branch information...
markstory committed Nov 1, 2012
1 parent 414e0a3 commit 1f31340a2a3f200a7bd8a9329ab22c38a7005397
@@ -383,6 +383,21 @@ protected function _setRuntimeData(Model $Model) {
$this->runtime[$Model->alias]['beforeSave'] = $tempData;
}
/**
* Restores model data to the original data.
* This solves issues with saveAssociated and validate = first.
*
* @param Model $model
* @return void
*/
public function afterValidate(Model $Model) {
$Model->data[$Model->alias] = array_merge(
$Model->data[$Model->alias],
$this->runtime[$Model->alias]['beforeSave']
);
return true;
}
/**
* afterSave Callback
*
@@ -530,6 +530,38 @@ public function testSaveCreate() {
$this->assertEquals($expected, $result);
}
/**
* testSaveAssociatedCreate method
*
* @return void
*/
public function testSaveAssociatedMultipleLocale() {
$this->loadFixtures('Translate', 'TranslatedItem');
$TestModel = new TranslatedItem();
$data = array(
'slug' => 'fourth_translated',
'title' => array(
'eng' => 'Title #4',
'spa' => 'Leyenda #4',
),
'content' => array(
'eng' => 'Content #4',
'spa' => 'Contenido #4',
),
'translated_article_id' => 1,
);
$TestModel->create();
$TestModel->saveAssociated($data);
$translations = array('title' => 'Title', 'content' => 'Content');
$TestModel->bindTranslation($translations, false);
$TestModel->locale = array('eng', 'spa');
$result = $TestModel->read();
$this->assertCount(2, $result['Title']);
$this->assertCount(2, $result['Content']);
}
/**
* Test that saving only some of the translated fields allows the record to be found again.
*

0 comments on commit 1f31340

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.