Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Modified Model::find() to make Model::findQueryType available in Mode…
…l callbacks. Fixes https://trac.cakephp.org/ticket/5847. Tests added

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information
tPl0ch authored and markstory committed Nov 4, 2009
1 parent 5a6a6e5 commit f5ca3ac
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cake/libs/model/model.php
Expand Up @@ -2079,12 +2079,13 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
}
$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 {
Expand Down
13 changes: 13 additions & 0 deletions cake/tests/cases/libs/model/model_read.test.php
Expand Up @@ -7151,5 +7151,18 @@ function testRecursiveFindAllWithLimit() {
);
$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');
}
}
?>
45 changes: 45 additions & 0 deletions cake/tests/cases/libs/model/models.php
Expand Up @@ -557,6 +557,51 @@ function afterFind($results) {
}
}

/**
* 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
*
Expand Down

0 comments on commit f5ca3ac

Please sign in to comment.