From 9577fb0ca247afa7f7aa335de7aa02e18230f98f Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 31 Jul 2011 01:07:46 +0530 Subject: [PATCH] Fixed TreeBehavior::childCount(). Closes #1833 --- lib/Cake/Model/Behavior/TreeBehavior.php | 2 +- lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 2ee639cf175..e467389c70b 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -219,7 +219,7 @@ public function childCount($Model, $id = null, $direct = false) { if ($id === null) { return $Model->find('count', array('conditions' => $scope)); - } elseif (isset($Model->data[$Model->alias][$left]) && isset($Model->data[$Model->alias][$right])) { + } elseif ($Model->id === $id && isset($Model->data[$Model->alias][$left]) && isset($Model->data[$Model->alias][$right])) { $data = $Model->data[$Model->alias]; } else { $data = $Model->find('first', array('conditions' => array($scope, $Model->escapeField() => $id), 'recursive' => $recursive)); diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index c21750ad1eb..3a325744871 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -1118,6 +1118,11 @@ public function testCountChildren() { $total = $this->Tree->childCount(); $this->assertEqual($total, 6); + + $this->Tree->read(null, $data[$modelClass]['id']); + $id = $this->Tree->field('id', array($modelClass . '.name' => '1.2')); + $total = $this->Tree->childCount($id); + $this->assertEqual($total, 2); } /**