Skip to content
Permalink
Browse files

Marking an enty as clean after the afterSave event.

By letting the entity be dirty during the event, listeners
can inspect the changes done to the entity during the save process.
I think this is a very important information to have and does not
negatively affect anything else.
  • Loading branch information...
lorenzo committed Jul 15, 2015
1 parent 9e35d06 commit 46fbae6420b9ca60a9e126194f08060540c3cebf
Showing with 3 additions and 1 deletion.
  1. +1 −1 src/ORM/Table.php
  2. +2 −0 tests/TestCase/ORM/TableTest.php
@@ -1445,8 +1445,8 @@ protected function _processSave($entity, $options)
['_primary' => false] + $options->getArrayCopy()
);
if ($success || !$options['atomic']) {
$entity->clean();
$this->dispatchEvent('Model.afterSave', compact('entity', 'options'));
$entity->clean();
if (!$options['atomic'] && !$options['_primary']) {
$entity->isNew(false);
$entity->source($this->registryAlias());
@@ -1888,13 +1888,15 @@ public function testAfterSave()
$called = false;
$listener = function ($e, $entity, $options) use ($data, &$called) {
$this->assertSame($data, $entity);
$this->assertTrue($entity->dirty());
$called = true;
};
$table->eventManager()->on('Model.afterSave', $listener);
$calledAfterCommit = false;
$listenerAfterCommit = function ($e, $entity, $options) use ($data, &$calledAfterCommit) {
$this->assertSame($data, $entity);
$this->assertFalse($entity->dirty());
$calledAfterCommit = true;
};
$table->eventManager()->on('Model.afterSaveCommit', $listenerAfterCommit);

0 comments on commit 46fbae6

Please sign in to comment.
You can’t perform that action at this time.