Skip to content
Permalink
Browse files

Fixed bug preventing afterSaveCommit from being fired during findOrCr…

…eate
  • Loading branch information...
jeremyharris committed Apr 30, 2018
1 parent 9b16f36 commit dd8b5ab3fb8ab17535da1440dbb88e6a2a6c590d
Showing with 5 additions and 5 deletions.
  1. +1 −3 src/ORM/Table.php
  2. +4 −2 tests/TestCase/ORM/TableTest.php
@@ -1680,9 +1680,7 @@ public function findOrCreate($search, callable $callback = null, $options = [])
'defaults' => true
];
return $this->_executeTransaction(function () use ($search, $callback, $options) {
return $this->_processFindOrCreate($search, $callback, $options);
}, $options['atomic']);
return $this->_processFindOrCreate($search, $callback, $options);
}
/**
@@ -6150,19 +6150,21 @@ public function testFindOrCreateNoDefaults()
public function testFindOrCreateTransactions()
{
$articles = $this->getTableLocator()->get('Articles');
$articles->getEventManager()->on('Model.afterSaveCommit', function ($event, $entity) {
$entity->afterSaveCommit = true;
});
$article = $articles->findOrCreate(function ($query) {
$this->assertInstanceOf('Cake\ORM\Query', $query);
$query->where(['title' => 'Find Something New']);
$this->assertTrue($this->connection->inTransaction());
}, function ($article) {
$this->assertInstanceOf('Cake\Datasource\EntityInterface', $article);
$this->assertTrue($this->connection->inTransaction());
$article->title = 'Success';
});
$this->assertFalse($article->isNew());
$this->assertNotNull($article->id);
$this->assertEquals('Success', $article->title);
$this->assertTrue($article->afterSaveCommit);
}
/**

0 comments on commit dd8b5ab

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