Skip to content
Permalink
Browse files

Fix association lazy-loading when used with ContainableBehavior

  • Loading branch information...
gjm authored and lorenzo committed Sep 29, 2011
1 parent 0b6c93c commit 4adc042882528a75b3a1a7f379a2cd710090bfc7
@@ -735,6 +735,11 @@ public function __isset($name) {
if (isset($name, $this->{$type}[$name])) {
$className = empty($this->{$type}[$name]['className']) ? $name : $this->{$type}[$name]['className'];
break;
}
elseif (isset($name, $this->__backAssociation[$type][$name])) {
$className = empty($this->__backAssociation[$type][$name]['className']) ?
$name : $this->__backAssociation[$type][$name]['className'];
break;
} else if ($type == 'hasAndBelongsToMany') {
foreach ($this->{$type} as $k => $relation) {
if (empty($relation['with'])) {
@@ -3588,6 +3588,29 @@ public function testFindAllReturn() {
$this->assertEmpty($result, 'Should be empty.');
}
/**
* testLazyLoad method
*
* @return void
*/
public function testLazyLoad() {
// Local set up
$this->User = ClassRegistry::init('User');
$this->User->bindModel(array(
'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
), false);
try {
$this->User->find('first', array(
'contain' => 'Comment',
'lazyLoad' => true
));
} catch (Exception $e) {
$exceptions = true;
}
$this->assertTrue(empty($exceptions));
}
/**
* containments method
*
@@ -179,6 +179,20 @@ class User extends CakeTestModel {
* @var array
*/
public $validate = array('user' => 'notEmpty', 'password' => 'notEmpty');
/**
* beforeFind() callback used to run ContainableBehaviorTest::testLazyLoad()
*
* @return bool
*/
public function beforeFind ($queryData) {
if (!empty($queryData['lazyLoad'])) {
if (!isset($this->Article, $this->Comment, $this->ArticleFeatured)) {
throw new Exception('Unavailable associations');
}
}
return true;
}
}
/**

0 comments on commit 4adc042

Please sign in to comment.
You can’t perform that action at this time.