mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
avoid warning when saveAll() data has empty hasMany data, fixes #2792
This commit is contained in:
parent
9556ff714d
commit
a84597784d
2 changed files with 22 additions and 0 deletions
|
@ -2036,6 +2036,9 @@ class Model extends Object implements CakeEventListener {
|
|||
|
||||
if (empty($data) && $options['validate'] !== false) {
|
||||
$result = $this->save($data, $options);
|
||||
if (!$options['atomic']) {
|
||||
return array(!empty($result));
|
||||
}
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
|
@ -2167,6 +2170,9 @@ class Model extends Object implements CakeEventListener {
|
|||
|
||||
if (empty($data) && $options['validate'] !== false) {
|
||||
$result = $this->save($data, $options);
|
||||
if (!$options['atomic']) {
|
||||
return array(!empty($result));
|
||||
}
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
|
|
|
@ -5228,6 +5228,22 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveAssociatedHasManyEmpty method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveAssociatedHasManyEmpty() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
$TestModel = new Article();
|
||||
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
|
||||
$result = $TestModel->saveAssociated(array(
|
||||
'Article' => array('title' => 'title', 'author_id' => 1),
|
||||
'Comment' => array()
|
||||
), array('validate' => true));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveAssociatedHasManyValidation method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue