Skip to content

Commit

Permalink
fix contain for find method
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Aug 13, 2012
1 parent 11227f5 commit e1fbfce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Behavior/ContainableBehavior.php
Expand Up @@ -171,7 +171,7 @@ public function beforeFind(Model $Model, $query) {
}

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']
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
Expand Up @@ -261,6 +261,30 @@ public function testContain() {
$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
*
Expand Down

0 comments on commit e1fbfce

Please sign in to comment.