Skip to content

Commit 7af9044

Browse files
committed
Automatically marking the recently saved entities as already persisted
1 parent 95fa5ef commit 7af9044

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Cake/ORM/Table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ protected function _processSave($entity, $options) {
730730
$id = $statement->lastInsertId($this->table(), $primary);
731731
$entity->set($primary, $id);
732732
$entity->clean();
733+
$entity->isNew(false);
733734
$success = $entity;
734735
}
735736

Cake/Test/TestCase/ORM/TableTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,4 +1305,21 @@ public function testsASavedEntityIsClean() {
13051305
$this->assertFalse($entity->dirty('updated'));
13061306
}
13071307

1308+
/**
1309+
* Tests that a recently saved entity is marked as not new
1310+
*
1311+
* @return void
1312+
*/
1313+
public function testsASavedEntityIsNotNew() {
1314+
$entity = new \Cake\ORM\Entity([
1315+
'username' => 'superuser',
1316+
'password' => 'root',
1317+
'created' => new \DateTime('2013-10-10 00:00'),
1318+
'updated' => new \DateTime('2013-10-10 00:00')
1319+
]);
1320+
$table = TableRegistry::get('users');
1321+
$this->assertSame($entity, $table->save($entity));
1322+
$this->assertFalse($entity->isNew());
1323+
}
1324+
13081325
}

0 commit comments

Comments
 (0)