Skip to content

Commit 86f22ab

Browse files
committed
Adding raw wheres
1 parent 23bc58d commit 86f22ab

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ You may also specify additional columns to update:
176176
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
177177
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));
178178

179+
**Raw Expressions**
180+
181+
These expressions will be injected directly into the query.
182+
183+
User::whereRaw(array('age' => array('$gt' => 30, '$lt' => 40)))->get();
184+
179185
**Query Caching**
180186

181187
You may easily cache the results of a query using the remember method:

Diff for: src/Jenssegers/Mongodb/Builder.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ private function compileWhereNotNull($where)
532532
return $this->compileWhereBasic($where);
533533
}
534534

535-
private function compileWherebetween($where)
535+
private function compileWhereBetween($where)
536536
{
537537
extract($where);
538538

@@ -543,4 +543,9 @@ private function compileWherebetween($where)
543543
);
544544
}
545545

546+
private function compileWhereRaw($where)
547+
{
548+
return $where['sql'];
549+
}
550+
546551
}

Diff for: tests/ModelQueryTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,18 @@ public function testInsertGetId()
322322
$this->assertTrue(is_string($id));
323323
}
324324

325+
public function testRaw()
326+
{
327+
$where = array('age' => array('$gt' => 30, '$lt' => 40));
328+
$users = User::whereRaw($where)->get();
329+
330+
$this->assertEquals(6, count($users));
331+
332+
$where1 = array('age' => array('$gt' => 30, '$lte' => 35));
333+
$where2 = array('age' => array('$gt' => 35, '$lt' => 40));
334+
$users = User::whereRaw($where1)->orWhereRaw($where2)->get();
335+
336+
$this->assertEquals(6, count($users));
337+
}
338+
325339
}

0 commit comments

Comments
 (0)