mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
5a6a6e5364
commit
f5ca3ace1f
3 changed files with 60 additions and 1 deletions
|
@ -2079,12 +2079,13 @@ class Model extends Overloadable {
|
||||||
}
|
}
|
||||||
$results = $db->read($this, $query);
|
$results = $db->read($this, $query);
|
||||||
$this->resetAssociations();
|
$this->resetAssociations();
|
||||||
$this->findQueryType = null;
|
|
||||||
|
|
||||||
if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
|
if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
|
||||||
$results = $this->__filterResults($results);
|
$results = $this->__filterResults($results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->findQueryType = null;
|
||||||
|
|
||||||
if ($type === 'all') {
|
if ($type === 'all') {
|
||||||
return $results;
|
return $results;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7151,5 +7151,18 @@ class ModelReadTest extends BaseModelTest {
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -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
|
* MergeVarPluginAppModel class
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue