Fixed TreeBehavior::childCount(). Closes #1833

This commit is contained in:
ADmad 2011-07-31 01:07:46 +05:30
parent 7a9ac53adf
commit 762fcf2c42
2 changed files with 7 additions and 2 deletions

View file

@ -226,7 +226,7 @@ class TreeBehavior extends ModelBehavior {
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));
@ -717,7 +717,7 @@ class TreeBehavior extends ModelBehavior {
$db =& ConnectionManager::getDataSource($Model->useDbConfig);
$Model->updateAll(
array($parent => $db->value($node[$parent], $parent)),
array($parent => $db->value($node[$parent], $parent)),
array($Model->escapeField($parent) => $node[$Model->primaryKey])
);
$this->__sync($Model, 1, '-', 'BETWEEN ' . ($node[$left] + 1) . ' AND ' . ($node[$right] - 1));

View file

@ -1112,6 +1112,11 @@ class NumberTreeTest extends CakeTestCase {
$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);
}
/**