Skip to content
Permalink
Browse files

Fixed TreeBehavior::childCount(). Closes #1833

  • Loading branch information...
ADmad committed Jul 30, 2011
1 parent 7a9ac53 commit 762fcf2c422f9af1b3902a1a914fa8675dd24547
Showing with 7 additions and 2 deletions.
  1. +2 −2 cake/libs/model/behaviors/tree.php
  2. +5 −0 cake/tests/cases/libs/model/behaviors/tree.test.php
@@ -226,7 +226,7 @@ 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));
@@ -717,7 +717,7 @@ function removefromtree(&$Model, $id = null, $delete = false) {
$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));
@@ -1112,6 +1112,11 @@ 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);
}
/**

0 comments on commit 762fcf2

Please sign in to comment.
You can’t perform that action at this time.