Skip to content

Commit

Permalink
Fixed TreeBehavior::childCount(). Closes #1833
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 31, 2011
1 parent eaa0163 commit 9577fb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 9577fb0

Please sign in to comment.