summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
authorLuis Ramón López <[email protected]>2014-01-02 21:54:58 +0100
committerSimon Holywell <[email protected]>2014-04-26 13:33:06 +0100
commitef4df3033fdd4fe6faeffeac112b36a24a7e2e96 (patch)
treefbf5bb68f4c1a806e9bb9708abb94df8eb2068b8 /idiorm.php
parent6a2cd02c81cf0ac61cbcbf256d1e7a8449543c31 (diff)
Add support for adding multi-column conditions into queries
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php26
1 files changed, 17 insertions, 9 deletions
diff --git a/idiorm.php b/idiorm.php
index 603bcb2..3795032 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -1017,19 +1017,27 @@
* style HAVING or WHERE condition into a string and value ready to
* be passed to the _add_condition method. Avoids duplication
* of the call to _quote_identifier
+ *
+ * If column_name is an associative array, it will add a condition for each column
*/
protected function _add_simple_condition($type, $column_name, $separator, $value) {
- // Add the table name in case of ambiguous columns
- if (count($this->_join_sources) > 0 && strpos($column_name, '.') === false) {
- $table = $this->_table_name;
- if (!is_null($this->_table_alias)) {
- $table = $this->_table_alias;
- }
+ $multiple = is_array($column_name) ? $column_name : array($column_name => $value);
+ $result = $this;
+
+ foreach($multiple as $key => $val) {
+ // Add the table name in case of ambiguous columns
+ if (count($result->_join_sources) > 0 && strpos($key, '.') === false) {
+ $table = $result->_table_name;
+ if (!is_null($result->_table_alias)) {
+ $table = $result->_table_alias;
+ }
- $column_name = "{$table}.{$column_name}";
+ $key = "{$table}.{$key}";
+ }
+ $key = $result->_quote_identifier($key);
+ $result = $result->_add_condition($type, "{$key} {$separator} ?", $val);
}
- $column_name = $this->_quote_identifier($column_name);
- return $this->_add_condition($type, "{$column_name} {$separator} ?", $value);
+ return $result;
}
/**