From 74a84c96f138b4c6e5ff88924f9998c0717cbc80 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Thu, 23 Feb 2012 00:56:20 +0000 Subject: [PATCH 1/2] optimization of tree behavior as per ticket #2600 --- lib/Cake/Model/Behavior/TreeBehavior.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index b4f807dec..53f1f2ad2 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -117,8 +117,9 @@ class TreeBehavior extends ModelBehavior { */ public function beforeDelete($Model, $cascade = true) { extract($this->settings[$Model->alias]); - list($name, $data) = array($Model->alias, $Model->read()); - $data = $data[$name]; + $data = current($Model->find('first', array( + 'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id), + 'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right)))); if (!$data[$right] || !$data[$left]) { return true; From c02912261bc23b956b195edacc362ff0b1b23c5d Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Thu, 23 Feb 2012 11:36:44 +0000 Subject: [PATCH 2/2] setting recursive to -1 --- lib/Cake/Model/Behavior/TreeBehavior.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 53f1f2ad2..6dea16dc6 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -119,7 +119,8 @@ class TreeBehavior extends ModelBehavior { extract($this->settings[$Model->alias]); $data = current($Model->find('first', array( 'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id), - 'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right)))); + 'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right), + 'recursive' => -1))); if (!$data[$right] || !$data[$left]) { return true;