From b2037343d908dbcf9f9d63d9ef97b4e47bf893b9 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Tue, 6 Nov 2012 09:03:03 -0500 Subject: [PATCH] Added ability to pass in an array of integers assumed to be ID's Previously new Model(array(1, 2, 3)); would results in a query like SELECT * FROM table WHERE 1 AND 2 AND 3; which would typically result in an out of memory error depending on the number of rows in the table (as all would be returned). Added detection for an array of integers and forces that to be considered new Model(array('id' => array(1, 2, 3))). As I type this I think I need to go back and make an additional change. --- classes/Model.php | 15 +++++++++++++++ jar.php | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/classes/Model.php b/classes/Model.php index 43bd82c..23b3fda 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -617,6 +617,21 @@ class Model extends Object // Adds the WHERE conditionals if ($this->conditions != false) { + $use_id = true; + + foreach ($this->conditions as $column => $value) + { + if (is_string($column) || is_string($value)) + { + $use_id = false; + } + } + + if ($use_id) + { + $this->conditions = array($this->columns['id'] => $this->conditions); + } + $this->sql[] = 'WHERE ' . (is_array($this->conditions) ? $this->generateConditions($this->conditions) : $this->conditions); } diff --git a/jar.php b/jar.php index 26c4865..5c07085 100755 --- a/jar.php +++ b/jar.php @@ -4682,6 +4682,21 @@ class Model extends Object // Adds the WHERE conditionals if ($this->conditions != false) { + $use_id = true; + + foreach ($this->conditions as $column => $value) + { + if (is_string($column) || is_string($value)) + { + $use_id = false; + } + } + + if ($use_id) + { + $this->conditions = array($this->columns['id'] => $this->conditions); + } + $this->sql[] = 'WHERE ' . (is_array($this->conditions) ? $this->generateConditions($this->conditions) : $this->conditions); }