diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 9c09e0f91..ce64d6c0c 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -212,7 +212,7 @@ class TreeBehavior extends ModelBehavior { 'fields' => array($Model->primaryKey, $parent, $left, $right), 'recursive' => $recursive) ); - if ($values === false) { + if (empty($values)) { return false; } list($node) = array_values($values); diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php index c7ea1fba2..5cf3e4cbf 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php @@ -130,6 +130,29 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->assertEquals(11, $this->Tree->find('count')); } +/** + * testSaveWithParentAndInvalidScope method + * + * Attempting to save an invalid data should not trigger an `Undefined offset` + * error + * + * @return void + */ + public function testSaveWithParentAndInvalidScope() { + $this->Tree = new FlagTree(); + $this->Tree->order = null; + $data = $this->Tree->create(array( + 'name' => 'Flag', + )); + $tree = $this->Tree->save($data); + $this->Tree->Behaviors->load('Tree', array( + 'scope' => array('FlagTree.flag' => 100) + )); + $tree['FlagTree']['parent_id'] = 1; + $result = $this->Tree->save($tree); + $this->assertFalse($result); + } + /** * testMoveUpWithScope method *