diff --git a/cake/libs/model/behaviors/containable.php b/cake/libs/model/behaviors/containable.php index 7d9a96536..f2e30f8c6 100644 --- a/cake/libs/model/behaviors/containable.php +++ b/cake/libs/model/behaviors/containable.php @@ -57,7 +57,7 @@ class ContainableBehavior extends ModelBehavior { * disables this feature. DEFAULTS TO: true * * - notices: (boolean, optional) issues E_NOTICES for bindings referenced in a - * containable call that are not valid. DEFAULTS TO: false + * containable call that are not valid. DEFAULTS TO: true * * - autoFields: (boolean, optional) auto-add needed fields to fetch requested * bindings. DEFAULTS TO: true @@ -297,8 +297,10 @@ class ContainableBehavior extends ModelBehavior { } } - if ($throwErrors && (!isset($Model->{$name}) || !is_object($Model->{$name}))) { - trigger_error(__(sprintf('Model "%s" is not associated with model "%s"', $Model->alias, $name), true), E_USER_WARNING); + if (!isset($Model->{$name}) || !is_object($Model->{$name})) { + if ($throwErrors) { + trigger_error(__(sprintf('Model "%s" is not associated with model "%s"', $Model->alias, $name), true), E_USER_WARNING); + } continue; } diff --git a/cake/tests/cases/libs/model/behaviors/containable.test.php b/cake/tests/cases/libs/model/behaviors/containable.test.php index 627defc63..ec000d02b 100644 --- a/cake/tests/cases/libs/model/behaviors/containable.test.php +++ b/cake/tests/cases/libs/model/behaviors/containable.test.php @@ -87,6 +87,14 @@ class ContainableTest extends CakeTestCase { $this->assertEqual(Set::extract('/ArticleFeatured/keep/Featured/fields', $r), array('id')); } + function testInvalidContainments() { + $this->expectError(); + $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); + + $this->Article->Behaviors->attach('Containable', array('notices' => false)); + $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); + } + function testBeforeFind() { $r = $this->Article->find('all', array('contain' => array('Comment'))); $this->assertFalse(Set::matches('/User', $r));