From e1fbfcef005a1b876fe527dbf9c03703bfece269 Mon Sep 17 00:00:00 2001 From: euromark Date: Mon, 13 Aug 2012 08:10:51 +0200 Subject: [PATCH] fix contain for find method --- .../Model/Behavior/ContainableBehavior.php | 2 +- .../Behavior/ContainableBehaviorTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/ContainableBehavior.php b/lib/Cake/Model/Behavior/ContainableBehavior.php index e81df035c..98989b64a 100644 --- a/lib/Cake/Model/Behavior/ContainableBehavior.php +++ b/lib/Cake/Model/Behavior/ContainableBehavior.php @@ -171,7 +171,7 @@ class ContainableBehavior extends ModelBehavior { } if ($this->settings[$Model->alias]['recursive']) { - $query['recursive'] = (isset($query['recursive'])) ? $query['recursive'] : $containments['depth']; + $query['recursive'] = (isset($query['recursive'])) ? max($query['recursive'], $containments['depth']) : $containments['depth']; } $autoFields = ($this->settings[$Model->alias]['autoFields'] diff --git a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php index 8345c87d6..aa8eee1f6 100644 --- a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php @@ -261,6 +261,30 @@ class ContainableBehaviorTest extends CakeTestCase { $this->assertFalse(Set::matches('/Comment/User', $r)); } +/** + * testContainFindList method + * + * @return void + */ + public function testContainFindList() { + $this->Article->contain('Comment.User'); + $result = $this->Article->find('list'); + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); + + $result = $this->Article->find('list', array('fields'=>array('Article.id', 'User.id'), 'contain'=>array('User'))); + $expected = array( + 1 => '1', + 2 => '3', + 3 => '1' + ); + $this->assertEquals($expected, $result); + } + /** * testFindEmbeddedNoBindings method *