mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #7086 from cakephp/issue-7069
Fix issues saveMany & saveAssociated with boolean values.
This commit is contained in:
commit
e19f621314
2 changed files with 94 additions and 4 deletions
|
@ -2335,7 +2335,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if ($options['deep']) {
|
||||
$saved = $this->saveAssociated($record, array('atomic' => false) + $options);
|
||||
} else {
|
||||
$saved = $this->save($record, array('atomic' => false) + $options);
|
||||
$saved = (bool)$this->save($record, array('atomic' => false) + $options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2478,7 +2478,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if ($options['deep']) {
|
||||
$saved = $Model->saveAssociated($values, array('atomic' => false) + $options);
|
||||
} else {
|
||||
$saved = $Model->save($values, array('atomic' => false) + $options);
|
||||
$saved = (bool)$Model->save($values, array('atomic' => false) + $options);
|
||||
}
|
||||
$validates = ($saved === true || (is_array($saved) && !in_array(false, Hash::flatten($saved), true)));
|
||||
}
|
||||
|
@ -2534,7 +2534,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if ($options['deep']) {
|
||||
$saved = $Model->saveAssociated($values, array('atomic' => false) + $options);
|
||||
} else {
|
||||
$saved = $Model->save($values, $options);
|
||||
$saved = (bool)$Model->save($values, $options);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7684,6 +7684,37 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEquals(2, count($result['Attachment']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that boolean fields don't cause saveMany to fail
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveManyBooleanFields() {
|
||||
$this->loadFixtures('Item', 'Syfile', 'Image');
|
||||
$data = array(
|
||||
array(
|
||||
'Item' => array(
|
||||
'name' => 'testing',
|
||||
'syfile_id' => 1,
|
||||
'published' => false
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Item' => array(
|
||||
'name' => 'testing 2',
|
||||
'syfile_id' => 1,
|
||||
'published' => true
|
||||
)
|
||||
),
|
||||
);
|
||||
$item = ClassRegistry::init('Item');
|
||||
$result = $item->saveMany($data, array('atomic' => false));
|
||||
|
||||
$this->assertCount(2, $result, '2 records should have been saved.');
|
||||
$this->assertTrue($result[0], 'Both should have succeded');
|
||||
$this->assertTrue($result[1], 'Both should have succeded');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveManyDeepHasManyValidationFailure method
|
||||
*
|
||||
|
@ -7806,6 +7837,65 @@ class ModelWriteTest extends BaseModelTest {
|
|||
), $TestModel->validationErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that boolean fields don't cause saveAssociated to fail
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveAssociatedHasOneBooleanFields() {
|
||||
$this->loadFixtures('Item', 'Syfile', 'Image');
|
||||
$data = array(
|
||||
'Syfile' => array(
|
||||
'image_id' => 1,
|
||||
'name' => 'Some file',
|
||||
),
|
||||
'Item' => array(
|
||||
'name' => 'testing',
|
||||
'published' => false
|
||||
),
|
||||
);
|
||||
$syfile = ClassRegistry::init('Syfile');
|
||||
$syfile->bindModel(array('hasOne' => array('Item')), false);
|
||||
$result = $syfile->saveAssociated($data, array('atomic' => false));
|
||||
|
||||
$this->assertCount(2, $result, '2 records should have been saved.');
|
||||
$this->assertTrue($result['Syfile'], 'Both should have succeded');
|
||||
$this->assertTrue($result['Item'], 'Both should have succeded');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that boolean fields don't cause saveAssociated to fail
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveAssociatedBelongsToBooleanFields() {
|
||||
$this->loadFixtures('Item', 'Syfile', 'Image');
|
||||
$data = array(
|
||||
'Syfile' => array(
|
||||
'image_id' => 1,
|
||||
'name' => 'Some file',
|
||||
),
|
||||
'Item' => array(
|
||||
'name' => 'testing',
|
||||
'syfile_id' => 2,
|
||||
'published' => false
|
||||
),
|
||||
);
|
||||
$item = ClassRegistry::init('Item');
|
||||
$item->bindModel(array(
|
||||
'belongsTo' => array(
|
||||
'Item' => array(
|
||||
'foreignKey' => 'image_id'
|
||||
)
|
||||
)
|
||||
), false);
|
||||
$result = $item->saveAssociated($data, array('atomic' => false));
|
||||
|
||||
$this->assertCount(2, $result, '2 records should have been saved.');
|
||||
$this->assertTrue($result['Syfile'], 'Both should have succeded');
|
||||
$this->assertTrue($result['Item'], 'Both should have succeded');
|
||||
}
|
||||
|
||||
/**
|
||||
* testUpdateAllBoolean
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue