Fixing issue where Containable was not resetting the original bindings properly when reset was false under some circumstances, fixes #4812

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7104 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-06-03 14:12:38 +00:00
parent 7dfb31200f
commit 2d2096d9f7
2 changed files with 34 additions and 1 deletions

View file

@ -102,7 +102,7 @@ class ContainableBehavior extends ModelBehavior {
if (isset($query['contain'])) {
$contain = array_merge($contain, (array)$query['contain']);
}
if ($noContain || (!$contain && !isset($Model->__backOriginalAssociation)) || in_array($contain, array(null, false), true) || (isset($contain[0]) && $contain[0] === null)) {
if ($noContain || !$contain || in_array($contain, array(null, false), true) || (isset($contain[0]) && $contain[0] === null)) {
if ($noContain) {
$query['recursive'] = -1;
}

View file

@ -3212,6 +3212,39 @@ class ContainableTest extends CakeTestCase {
$this->assertTrue(Set::matches('/User[id=1]', $r));
$this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
$this->assertTrue(Set::matches('/Comment[id=1]', $r));
$this->Article->bindModel(array('hasAndBelongsToMany' => array('Tag')), false);
$this->Article->contain(false, array('User(id,user)', 'Comment' => array('fields' => array('comment'), 'conditions' => array('created >=' => '2007-03-18 10:49'))));
$result = $this->Article->find('all', array('fields' => array('title'), 'limit' => 1, 'page' => 1, 'order' => 'Article.id ASC'));
$expected = array(array(
'Article' => array('id' => 1, 'title' => 'First Article'),
'User' => array('id' => 1, 'user' => 'mariano'),
'Comment' => array(
array('comment' => 'Third Comment for First Article', 'article_id' => 1),
array('comment' => 'Fourth Comment for First Article', 'article_id' => 1)
)
));
$this->assertEqual($result, $expected);
$result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 2, 'order' => 'Article.id ASC'));
$expected = array(array(
'Article' => array('id' => 2, 'title' => 'Second Article'),
'User' => array('id' => 3, 'user' => 'larry'),
'Comment' => array(
array('comment' => 'First Comment for Second Article', 'article_id' => 2),
array('comment' => 'Second Comment for Second Article', 'article_id' => 2)
)
));
$this->assertEqual($result, $expected);
$result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 3, 'order' => 'Article.id ASC'));
$expected = array(array(
'Article' => array('id' => 3, 'title' => 'Third Article'),
'User' => array('id' => 1, 'user' => 'mariano'),
'Comment' => array()
));
$this->assertEqual($result, $expected);
}
function __containments(&$Model, $contain = array()) {