Skip to content

Commit

Permalink
Ensure that afterFind is called when using 'joins' with 'recursive' = -1
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed Aug 27, 2014
1 parent b74774b commit 3120483
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1143,10 +1143,10 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
}
}
}
}

if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') {
$this->_filterResults($resultSet, $Model, $filtered);
}
if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') {
$this->_filterResults($resultSet, $Model, $filtered);
}

if ($recursive !== null) {
Expand Down
51 changes: 51 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -1509,6 +1509,57 @@ public function testCountAfterFindCalls() {
$this->assertCount(2, $result['Article']['Comment']);
}

/**
* Test that afterFind is called correctly for 'joins'
*
* @return void
*/
public function testJoinsAfterFind() {
$this->loadFixtures('Article', 'User');

$User = new User();
$User->bindModel(array('hasOne' => array('Article')));

$Article = $this->getMock('Article', array('afterFind'), array(), '', true);
$Article->expects($this->once())
->method('afterFind')
->with(
array(
0 => array(
'Article' => array(
'id' => '1',
'user_id' => '1',
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)
)
),
$this->isFalse()
)
->will($this->returnArgument(0));

$User->Article = $Article;
$User->find('first', array(
'fields' => '*',
'conditions' => array('User.id' => 1),
'recursive' => -1,
'joins' => array(
array(
'table' => 'articles',
'alias' => 'Article',
'type' => 'LEFT',
'conditions' => array(
'Article.user_id = User.id'
),
)
),
'order' => array('Article.id')
));
}

/**
* Test that afterFind is called correctly for 'hasOne' association.
*
Expand Down

0 comments on commit 3120483

Please sign in to comment.