Browse Source

Mongo query "IN" condition shortcut syntax added.

tags/2.0.0-beta
Klimov Paul 11 years ago
parent
commit
dc3ada65a5
  1. 8
      extensions/mongo/Collection.php
  2. 4
      tests/unit/extensions/mongo/QueryRunTest.php

8
extensions/mongo/Collection.php

@ -242,7 +242,13 @@ class Collection extends Object
if (is_numeric($key)) { if (is_numeric($key)) {
$result[] = $actualValue; $result[] = $actualValue;
} else { } else {
$result[$this->normalizeConditionKeyword($key)] = $actualValue; $key = $this->normalizeConditionKeyword($key);
if (strncmp('$', $key, 1) !== 0 && array_key_exists(0, $actualValue)) {
// shortcut for IN condition
$result[$key]['$in'] = $actualValue;
} else {
$result[$key] = $actualValue;
}
} }
} }
return $result; return $result;

4
tests/unit/extensions/mongo/QueryRunTest.php

@ -75,9 +75,7 @@ class QueryRunTest extends MongoTestCase
$query = new Query; $query = new Query;
$rows = $query->from('customer') $rows = $query->from('customer')
->where([ ->where([
'name' => [ 'name' => ['name1', 'name5']
'in' => ['name1', 'name5']
]
]) ])
->all($connection); ->all($connection);
$this->assertEquals(2, count($rows)); $this->assertEquals(2, count($rows));

Loading…
Cancel
Save