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:
mark_story 2012-12-16 13:18:59 -05:00
parent 71371dd9da
commit 1528b5c382
2 changed files with 22 additions and 0 deletions

View file

@ -1749,6 +1749,10 @@ class Model extends Object implements CakeEventListener {
$this->_saveMulti($joined, $this->id, $db); $this->_saveMulti($joined, $this->id, $db);
} }
if ($success && $count === 0) {
$success = false;
}
if ($success && $count > 0) { if ($success && $count > 0) {
if (!empty($this->data)) { if (!empty($this->data)) {
if ($created) { if ($created) {

View file

@ -24,6 +24,24 @@ require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
*/ */
class ModelWriteTest extends BaseModelTest { 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 * testInsertAnotherHabtmRecordWithSameForeignKey method
* *