Commit 86f22ab3 authored by Jens Segers's avatar Jens Segers

Adding raw wheres

parent 23bc58de
......@@ -176,6 +176,12 @@ You may also specify additional columns to update:
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));
**Raw Expressions**
These expressions will be injected directly into the query.
User::whereRaw(array('age' => array('$gt' => 30, '$lt' => 40)))->get();
**Query Caching**
You may easily cache the results of a query using the remember method:
......
......@@ -532,7 +532,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
return $this->compileWhereBasic($where);
}
private function compileWherebetween($where)
private function compileWhereBetween($where)
{
extract($where);
......@@ -543,4 +543,9 @@ class Builder extends \Illuminate\Database\Query\Builder {
);
}
private function compileWhereRaw($where)
{
return $where['sql'];
}
}
\ No newline at end of file
......@@ -322,4 +322,18 @@ class ModelQueryTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(is_string($id));
}
public function testRaw()
{
$where = array('age' => array('$gt' => 30, '$lt' => 40));
$users = User::whereRaw($where)->get();
$this->assertEquals(6, count($users));
$where1 = array('age' => array('$gt' => 30, '$lte' => 35));
$where2 = array('age' => array('$gt' => 35, '$lt' => 40));
$users = User::whereRaw($where1)->orWhereRaw($where2)->get();
$this->assertEquals(6, count($users));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment