Permalink
Browse files

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...
1 parent 5a6a6e5 commit f5ca3ace1ffaed36f72c782baf5c731f13840293 tPl0ch committed with markstory Nov 1, 2009
@@ -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 {
@@ -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');
+ }
}
?>
@@ -558,6 +558,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
*
* @package cake

0 comments on commit f5ca3ac

Please sign in to comment.