mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Fix for Model::saveAll bug, closes #4466
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6823 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0b1f7b9151
commit
232e3f7ec1
3 changed files with 39 additions and 0 deletions
|
@ -1365,6 +1365,9 @@ class Model extends Overloadable {
|
||||||
$return[$this->alias][] = $validates;
|
$return[$this->alias][] = $validates;
|
||||||
}
|
}
|
||||||
foreach ($data as $association => $values) {
|
foreach ($data as $association => $values) {
|
||||||
|
if (!$validates) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (isset($associations[$association])) {
|
if (isset($associations[$association])) {
|
||||||
$type = $associations[$association];
|
$type = $associations[$association];
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
|
|
@ -2142,6 +2142,37 @@ class ModelTest extends CakeTestCase {
|
||||||
$result = $this->model->findById(2);
|
$result = $this->model->findById(2);
|
||||||
$expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment');
|
$expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment');
|
||||||
$this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected);
|
$this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected);
|
||||||
|
|
||||||
|
$result = $this->model->saveAll(
|
||||||
|
array(
|
||||||
|
'Article' => array('id' => 2),
|
||||||
|
'Comment' => array(
|
||||||
|
array('comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array('atomic' => false)
|
||||||
|
);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$result = $this->model->findById(2);
|
||||||
|
$expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment');
|
||||||
|
$this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected);
|
||||||
|
|
||||||
|
$this->model->beforeSaveReturn = false;
|
||||||
|
$result = $this->model->saveAll(
|
||||||
|
array(
|
||||||
|
'Article' => array('id' => 2),
|
||||||
|
'Comment' => array(
|
||||||
|
array('comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array('atomic' => false)
|
||||||
|
);
|
||||||
|
$this->assertEqual($result, array('Article' => array(0 => false)));
|
||||||
|
|
||||||
|
$result = $this->model->findById(2);
|
||||||
|
$expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment');
|
||||||
|
$this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSaveAllTransaction() {
|
function testSaveAllTransaction() {
|
||||||
|
|
|
@ -101,6 +101,11 @@ class Article extends CakeTestModel {
|
||||||
var $hasMany = array('Comment' => array('dependent' => true));
|
var $hasMany = array('Comment' => array('dependent' => true));
|
||||||
var $hasAndBelongsToMany = array('Tag');
|
var $hasAndBelongsToMany = array('Tag');
|
||||||
var $validate = array('user_id' => VALID_NUMBER, 'title' => array('allowEmpty' => false, 'rule' => VALID_NOT_EMPTY), 'body' => VALID_NOT_EMPTY);
|
var $validate = array('user_id' => VALID_NUMBER, 'title' => array('allowEmpty' => false, 'rule' => VALID_NOT_EMPTY), 'body' => VALID_NOT_EMPTY);
|
||||||
|
var $beforeSaveReturn = true;
|
||||||
|
|
||||||
|
function beforeSave() {
|
||||||
|
return $this->beforeSaveReturn;
|
||||||
|
}
|
||||||
|
|
||||||
function titleDuplicate ($title) {
|
function titleDuplicate ($title) {
|
||||||
if ($title === 'My Article Title') {
|
if ($title === 'My Article Title') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue