diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index fa9fc3644..58b466188 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -2079,12 +2079,13 @@ class Model extends Overloadable { } $results = $db->read($this, $query); $this->resetAssociations(); - $this->findQueryType = null; if ($query['callbacks'] === true || $query['callbacks'] === 'after') { $results = $this->__filterResults($results); } + $this->findQueryType = null; + if ($type === 'all') { return $results; } else { diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index b977c8956..28411f21a 100644 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -7151,5 +7151,18 @@ class ModelReadTest extends BaseModelTest { ); $this->assertEqual($result, $expected); } +/** + * Testing availability of $this->findQueryType in Model callbacks + * + * @return void + */ + function testFindQueryTypeInCallbacks() { + $this->loadFixtures('Comment'); + $Comment =& new AgainModifiedComment(); + $comments = $Comment->find('all'); + $this->assertEqual($comments[0]['Comment']['querytype'], 'all'); + $comments = $Comment->find('first'); + $this->assertEqual($comments['Comment']['querytype'], 'first'); + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 20262d74b..3078b403c 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -557,6 +557,51 @@ class ModifiedComment extends CakeTestModel { } } +/** + * Modified Comment Class has afterFind Callback + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class AgainModifiedComment extends CakeTestModel { + +/** + * name property + * + * @var string 'Comment' + * @access public + */ + var $name = 'Comment'; + +/** + * useTable property + * + * @var string 'comments' + * @access public + */ + var $useTable = 'comments'; + +/** + * belongsTo property + * + * @var array + * @access public + */ + var $belongsTo = array('Article'); + +/** + * afterFind callback + * + * @return void + **/ + function afterFind($results) { + if (isset($results[0])) { + $results[0]['Comment']['querytype'] = $this->findQueryType; + } + return $results; + } +} + /** * MergeVarPluginAppModel class *