Modified Model::find() to make Model::findQueryType available in Model callbacks. Fixes https://trac.cakephp.org/ticket/5847. Tests added

Signed-off-by: Mark Story <mark@mark-story.com>
This commit is contained in:
tPl0ch 2009-11-01 15:08:39 +01:00 committed by mark_story
parent 5a6a6e5364
commit f5ca3ace1f
3 changed files with 60 additions and 1 deletions

View file

@ -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 {

View file

@ -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');
}
}
?>

View file

@ -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
*