From 31204832c2fbdfacf0ddaa018ac28871f788a2aa Mon Sep 17 00:00:00 2001 From: chinpei215 Date: Wed, 27 Aug 2014 15:09:58 +0900 Subject: [PATCH] Ensure that afterFind is called when using 'joins' with 'recursive' = -1 --- lib/Cake/Model/Datasource/DboSource.php | 6 +-- .../Case/Model/Datasource/DboSourceTest.php | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 6bc5780b3..25c2c69df 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1143,10 +1143,10 @@ class DboSource extends DataSource { } } } + } - 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) { diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index ffc48c765..17cf005f5 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -1509,6 +1509,57 @@ class DboSourceTest extends CakeTestCase { $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. *