Skip to content
This repository
Browse code

fix contain for find method

  • Loading branch information...
commit e1fbfcef005a1b876fe527dbf9c03703bfece269 1 parent 11227f5
Mark authored August 13, 2012
2  lib/Cake/Model/Behavior/ContainableBehavior.php
@@ -171,7 +171,7 @@ public function beforeFind(Model $Model, $query) {
171 171
 		}
172 172
 
173 173
 		if ($this->settings[$Model->alias]['recursive']) {
174  
-			$query['recursive'] = (isset($query['recursive'])) ? $query['recursive'] : $containments['depth'];
  174
+			$query['recursive'] = (isset($query['recursive'])) ? max($query['recursive'], $containments['depth']) : $containments['depth'];
175 175
 		}
176 176
 
177 177
 		$autoFields = ($this->settings[$Model->alias]['autoFields']
24  lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
@@ -262,6 +262,30 @@ public function testContain() {
262 262
 	}
263 263
 
264 264
 /**
  265
+ * testContainFindList method
  266
+ *
  267
+ * @return void
  268
+ */
  269
+	public function testContainFindList() {
  270
+		$this->Article->contain('Comment.User');
  271
+		$result = $this->Article->find('list');
  272
+		$expected = array(
  273
+			1 => 'First Article',
  274
+			2 => 'Second Article',
  275
+			3 => 'Third Article'
  276
+		);
  277
+		$this->assertEquals($expected, $result);
  278
+
  279
+		$result = $this->Article->find('list', array('fields'=>array('Article.id', 'User.id'), 'contain'=>array('User')));
  280
+		$expected = array(
  281
+			1 => '1',
  282
+			2 => '3',
  283
+			3 => '1'
  284
+		);
  285
+		$this->assertEquals($expected, $result);
  286
+	}
  287
+
  288
+/**
265 289
  * testFindEmbeddedNoBindings method
266 290
  *
267 291
  * @return void

0 notes on commit e1fbfce

Please sign in to comment.
Something went wrong with that request. Please try again.