From cf18e8d38b4cb0f7646d3cacc721132e81e20826 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Tue, 19 Jun 2012 15:53:39 +0200 Subject: [PATCH] avoid unneeded query in delete() --- lib/Cake/Model/Model.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 6a0083fe1..756e908d8 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2440,13 +2440,14 @@ class Model extends Object implements CakeEventListener { break; } } - - $keys = $this->find('first', array( - 'fields' => $this->_collectForeignKeys(), - 'conditions' => array($this->alias . '.' . $this->primaryKey => $id), - 'recursive' => -1, - 'callbacks' => false - )); + if ($updateCounterCache) { + $keys = $this->find('first', array( + 'fields' => $this->_collectForeignKeys(), + 'conditions' => array($this->alias . '.' . $this->primaryKey => $id), + 'recursive' => -1, + 'callbacks' => false + )); + } } if ($db->delete($this, array($this->alias . '.' . $this->primaryKey => $id))) {