mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Don't return true when there is nothing to save.
Model::save() should not return true when no work has been done. Fixes #3469
This commit is contained in:
parent
71371dd9da
commit
1528b5c382
2 changed files with 22 additions and 0 deletions
|
@ -1749,6 +1749,10 @@ class Model extends Object implements CakeEventListener {
|
|||
$this->_saveMulti($joined, $this->id, $db);
|
||||
}
|
||||
|
||||
if ($success && $count === 0) {
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ($success && $count > 0) {
|
||||
if (!empty($this->data)) {
|
||||
if ($created) {
|
||||
|
|
|
@ -24,6 +24,24 @@ require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
|
|||
*/
|
||||
class ModelWriteTest extends BaseModelTest {
|
||||
|
||||
/**
|
||||
* Test save() failing when there is no data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInsertNoData() {
|
||||
$this->loadFixtures('Bid');
|
||||
$Bid = ClassRegistry::init('Bid');
|
||||
|
||||
$this->assertFalse($Bid->save());
|
||||
|
||||
$result = $Bid->save(array('Bid' => array()));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $Bid->save(array('Bid' => array('not in schema' => 1)));
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testInsertAnotherHabtmRecordWithSameForeignKey method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue