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.
This commit is contained in:
parent
8da54b14ea
commit
b2037343d9
2 changed files with 30 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue