Skip to content

Commit

Permalink
Fixed bug preventing afterSaveCommit from being fired during findOrCr…
Browse files Browse the repository at this point in the history
…eate
  • Loading branch information
jeremyharris committed Apr 30, 2018
1 parent 9b16f36 commit dd8b5ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/ORM/Table.php
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit dd8b5ab

Please sign in to comment.