Skip to content

Commit b3eb81c

Browse files
committed
Add support for associative args in where condition
Signed-off-by: Kirtan Gajjar <[email protected]>
1 parent d455c2f commit b3eb81c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

php/class-ee-db.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ private function common_retrieval_function() {
197197
* [ 'id', '<', 100 ],
198198
* [ 'name', 'ee' ]
199199
* ])
200+
* or where([
201+
* 'id' => 100,
202+
* 'name' => 'ee',
203+
* ])
200204
*
201205
* Supported operators are: '=', '<', '>', '<=', '>=', '==', '!=', '<>', 'like', 'in'
202206
*
@@ -211,8 +215,15 @@ public function where( ...$args ) {
211215
$conditions = [];
212216

213217
if ( 'array' === gettype( $args[0] ) ) {
214-
foreach ( $args[0] as $condition ) {
215-
$conditions[] = $this->get_where_fragment( $condition );
218+
if ( \EE\Utils\is_assoc( $args[0] ) ) {
219+
$condition_keys = array_keys( $args[0] );
220+
foreach ( $condition_keys as $key ) {
221+
$conditions[] = $this->get_where_fragment( [ $key, $args[0][ $key ] ] );
222+
}
223+
} else {
224+
foreach ( $args[0] as $condition ) {
225+
$conditions[] = $this->get_where_fragment( $condition );
226+
}
216227
}
217228
} else {
218229
$conditions[] = $this->get_where_fragment( $args );

0 commit comments

Comments
 (0)