Skip to content

Commit 3120483

Browse files
committed
Ensure that afterFind is called when using 'joins' with 'recursive' = -1
1 parent b74774b commit 3120483

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

lib/Cake/Model/Datasource/DboSource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,10 +1143,10 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
11431143
}
11441144
}
11451145
}
1146+
}
11461147

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

11521152
if ($recursive !== null) {

lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,57 @@ public function testCountAfterFindCalls() {
15091509
$this->assertCount(2, $result['Article']['Comment']);
15101510
}
15111511

1512+
/**
1513+
* Test that afterFind is called correctly for 'joins'
1514+
*
1515+
* @return void
1516+
*/
1517+
public function testJoinsAfterFind() {
1518+
$this->loadFixtures('Article', 'User');
1519+
1520+
$User = new User();
1521+
$User->bindModel(array('hasOne' => array('Article')));
1522+
1523+
$Article = $this->getMock('Article', array('afterFind'), array(), '', true);
1524+
$Article->expects($this->once())
1525+
->method('afterFind')
1526+
->with(
1527+
array(
1528+
0 => array(
1529+
'Article' => array(
1530+
'id' => '1',
1531+
'user_id' => '1',
1532+
'title' => 'First Article',
1533+
'body' => 'First Article Body',
1534+
'published' => 'Y',
1535+
'created' => '2007-03-18 10:39:23',
1536+
'updated' => '2007-03-18 10:41:31'
1537+
)
1538+
)
1539+
),
1540+
$this->isFalse()
1541+
)
1542+
->will($this->returnArgument(0));
1543+
1544+
$User->Article = $Article;
1545+
$User->find('first', array(
1546+
'fields' => '*',
1547+
'conditions' => array('User.id' => 1),
1548+
'recursive' => -1,
1549+
'joins' => array(
1550+
array(
1551+
'table' => 'articles',
1552+
'alias' => 'Article',
1553+
'type' => 'LEFT',
1554+
'conditions' => array(
1555+
'Article.user_id = User.id'
1556+
),
1557+
)
1558+
),
1559+
'order' => array('Article.id')
1560+
));
1561+
}
1562+
15121563
/**
15131564
* Test that afterFind is called correctly for 'hasOne' association.
15141565
*

0 commit comments

Comments
 (0)