Skip to content
Permalink
Browse files

Don't return true when there is nothing to save.

Model::save() should not return true when no work has been done.

Fixes #3469
  • Loading branch information...
markstory committed Dec 16, 2012
1 parent 71371dd commit 1528b5c3820ca97acc989438f283d74b125cc4af
Showing with 22 additions and 0 deletions.
  1. +4 −0 lib/Cake/Model/Model.php
  2. +18 −0 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -1749,6 +1749,10 @@ public function save($data = null, $validate = true, $fieldList = array()) {
$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 @@
*/
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
*

0 comments on commit 1528b5c

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.