Skip to content

Commit

Permalink
Automatically marking the recently saved entities as already persisted
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 26, 2013
1 parent 95fa5ef commit 7af9044
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cake/ORM/Table.php
Expand Up @@ -730,6 +730,7 @@ protected function _processSave($entity, $options) {
$id = $statement->lastInsertId($this->table(), $primary);
$entity->set($primary, $id);
$entity->clean();
$entity->isNew(false);
$success = $entity;
}

Expand Down
17 changes: 17 additions & 0 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -1305,4 +1305,21 @@ public function testsASavedEntityIsClean() {
$this->assertFalse($entity->dirty('updated'));
}

/**
* Tests that a recently saved entity is marked as not new
*
* @return void
*/
public function testsASavedEntityIsNotNew() {
$entity = new \Cake\ORM\Entity([
'username' => 'superuser',
'password' => 'root',
'created' => new \DateTime('2013-10-10 00:00'),
'updated' => new \DateTime('2013-10-10 00:00')
]);
$table = TableRegistry::get('users');
$this->assertSame($entity, $table->save($entity));
$this->assertFalse($entity->isNew());
}

}

0 comments on commit 7af9044

Please sign in to comment.