Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make beforeFind triggered by associations use ArrayObject too
  • Loading branch information
ndm2 authored and markstory committed Jan 17, 2015
1 parent eea4544 commit 395de81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ORM/Association.php
Expand Up @@ -611,7 +611,7 @@ protected function _dispatchBeforeFind($query)
{
$table = $this->target();
$options = $query->getOptions();
$table->dispatchEvent('Model.beforeFind', [$query, $options, false]);
$table->dispatchEvent('Model.beforeFind', [$query, new \ArrayObject($options), false]);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/TestCase/ORM/TableTest.php
Expand Up @@ -3391,8 +3391,19 @@ public function testValidateUniqueScope()
public function testCallbackArgumentTypes()
{
$table = TableRegistry::get('articles');
$table->belongsTo('authors');

$eventManager = $table->eventManager();

$associationBeforeFindCount = 0;
$table->association('authors')->target()->eventManager()->attach(
function (Event $event, Query $query, ArrayObject $options, $primary) use (&$associationBeforeFindCount) {
$this->assertTrue(is_bool($primary));
$associationBeforeFindCount ++;
},
'Model.beforeFind'
);

$beforeFindCount = 0;
$eventManager->attach(
function (Event $event, Query $query, ArrayObject $options, $primary) use (&$beforeFindCount) {
Expand All @@ -3401,7 +3412,8 @@ function (Event $event, Query $query, ArrayObject $options, $primary) use (&$bef
},
'Model.beforeFind'
);
$table->find()->first();
$table->find()->contain('authors')->first();
$this->assertEquals(1, $associationBeforeFindCount);
$this->assertEquals(1, $beforeFindCount);

$buildValidatorCount = 0;
Expand Down

0 comments on commit 395de81

Please sign in to comment.