diff options
author | Luis Ramón López <[email protected]> | 2014-01-02 22:30:54 +0100 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2014-04-26 13:33:06 +0100 |
commit | d09ab6427f1ea7c3c46e91dabb4914b65b37bff0 (patch) | |
tree | a376f77482b269fe2c64949d7205247f19d32c12 /idiorm.php | |
parent | 73fb4ea1865f6404f60ac63930056b8b92ef1987 (diff) |
UPDATE queries are now compound primary keys aware
Diffstat (limited to 'idiorm.php')
-rw-r--r-- | idiorm.php | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -1838,7 +1838,12 @@ return true; } $query = $this->_build_update(); - $values[] = $this->id(); + $id = $this->id(); + if (is_array($id)) { + $values = array_merge($values, array_values($id)); + } else { + $values[] = $id; + } } else { // INSERT $query = $this->_build_insert(); } @@ -1863,6 +1868,25 @@ } /** + * Add a WHERE clause for every column that belongs to the primary key + */ + public function _add_id_column_conditions(&$query) { + $query[] = "WHERE"; + $keys = is_array($this->_get_id_column_name()) ? $this->_get_id_column_name() : array( $this->_get_id_column_name() ); + $first = true; + foreach($keys as $key) { + if ($first) { + $first = false; + } + else { + $query[] = "AND"; + } + $query[] = $this->_quote_identifier($key); + $query[] = "= ?"; + } + } + + /** * Build an UPDATE query */ protected function _build_update() { @@ -1877,9 +1901,7 @@ $field_list[] = "{$this->_quote_identifier($key)} = $value"; } $query[] = join(", ", $field_list); - $query[] = "WHERE"; - $query[] = $this->_quote_identifier($this->_get_id_column_name()); - $query[] = "= ?"; + $this->_add_id_column_conditions($query); return join(" ", $query); } |