Fixed TreeBehavior::childCount(). Closes #1833

This commit is contained in:
ADmad 2011-07-31 01:07:46 +05:30
parent eaa01634b1
commit 9577fb0ca2
2 changed files with 6 additions and 1 deletions

View file

@ -219,7 +219,7 @@ class TreeBehavior extends ModelBehavior {
if ($id === null) { if ($id === null) {
return $Model->find('count', array('conditions' => $scope)); 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]; $data = $Model->data[$Model->alias];
} else { } else {
$data = $Model->find('first', array('conditions' => array($scope, $Model->escapeField() => $id), 'recursive' => $recursive)); $data = $Model->find('first', array('conditions' => array($scope, $Model->escapeField() => $id), 'recursive' => $recursive));

View file

@ -1118,6 +1118,11 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$total = $this->Tree->childCount(); $total = $this->Tree->childCount();
$this->assertEqual($total, 6); $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);
} }
/** /**