diff options
-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); } |