mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-12 15:06:27 +00:00
Fix associated translations being inserted.
Due to changes introduced in [1c0b6c076a
]
associated translations would incorrectly be saved with a value of ''.
Fixes #3057
This commit is contained in:
parent
6286b43329
commit
e6ef218600
2 changed files with 37 additions and 7 deletions
|
@ -395,9 +395,12 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
|
|
||||||
$fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']);
|
$fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']);
|
||||||
if ($created) {
|
if ($created) {
|
||||||
foreach ($fields as $field) {
|
// set each field value to an empty string
|
||||||
|
foreach ($fields as $key => $field) {
|
||||||
|
if (!is_numeric($key)) {
|
||||||
|
$field = $key;
|
||||||
|
}
|
||||||
if (!isset($tempData[$field])) {
|
if (!isset($tempData[$field])) {
|
||||||
//set the field value to an empty string
|
|
||||||
$tempData[$field] = '';
|
$tempData[$field] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* TranslateBehaviorTest file
|
|
||||||
*
|
|
||||||
* PHP 5
|
|
||||||
*
|
|
||||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
*
|
*
|
||||||
|
@ -12,7 +8,6 @@
|
||||||
*
|
*
|
||||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||||
* @package Cake.Test.Case.Model.Behavior
|
|
||||||
* @since CakePHP(tm) v 1.2.0.5669
|
* @since CakePHP(tm) v 1.2.0.5669
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
@ -1058,4 +1053,36 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
$this->assertNotContains('slug', $result);
|
$this->assertNotContains('slug', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that additional records are not inserted for associated translations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNoExtraRowsForAssociatedTranslations() {
|
||||||
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
$TestModel = new TranslatedItem();
|
||||||
|
$TestModel->locale = 'spa';
|
||||||
|
$TestModel->unbindTranslation();
|
||||||
|
$TestModel->bindTranslation(array('name' => 'nameTranslate'));
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'TranslatedItem' => array(
|
||||||
|
'slug' => 'spanish-name',
|
||||||
|
'name' => 'Spanish name',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$TestModel->create($data);
|
||||||
|
$TestModel->save();
|
||||||
|
|
||||||
|
$Translate = $TestModel->translateModel();
|
||||||
|
$results = $Translate->find('all', array(
|
||||||
|
'conditions' => array(
|
||||||
|
'locale' => $TestModel->locale,
|
||||||
|
'foreign_key' => $TestModel->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$this->assertCount(1, $results, 'Only one field should be saved');
|
||||||
|
$this->assertEquals('name', $results[0]['TranslateTestModel']['field']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue