Added countReset option that defaults to false, fixes #4694

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6979 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-20 01:01:11 +00:00
parent 44470c2e72
commit aa00e47fe8
2 changed files with 11 additions and 3 deletions

View file

@ -61,6 +61,11 @@ class ContainableBehavior extends ModelBehavior {
*
* - autoFields: (boolean, optional) auto-add needed fields to fetch requested
* bindings. DEFAULTS TO: true
*
* - countReset: (boolean, optional) If set to false, count queries will not reset containments
* like normal queries would. Useful for using contain() and pagination.
* DEFAULTS TO: false
*
* @param object $Model Model using the behavior
* @param array $settings Settings to override for model.
@ -68,7 +73,7 @@ class ContainableBehavior extends ModelBehavior {
*/
function setup(&$Model, $settings = array()) {
if (!isset($this->settings[$Model->alias])) {
$this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true);
$this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true, 'countReset' => false);
}
$this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], ife(is_array($settings), $settings, array()));
}
@ -92,7 +97,10 @@ class ContainableBehavior extends ModelBehavior {
* @access public
*/
function beforeFind(&$Model, $query) {
$reset = (isset($query['reset']) ? $query['reset'] : true);
$reset = $this->settings[$Model->alias]['countReset'] || $Model->findQueryType != 'count';
if (isset($query['reset'])) {
$reset = $query['reset'];
}
$noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain'])));
$contain = array();
if (isset($this->runtime[$Model->alias]['contain'])) {

View file

@ -2931,7 +2931,7 @@ class ContainableTest extends CakeTestCase {
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->paginate = array('Article' => array('fields' => array('title')));
$Controller->Article->contain(false, array('User(user)'));
$Controller->Article->contain(array('User(user)'));
$result = $Controller->paginate('Article');
$Controller->Article->resetBindings();
$expected = array(