Skip to content

Commit c933300

Browse files
committed
Preparing for laravel 4.1, fixes #60
1 parent 1089ee3 commit c933300

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
}
2626
},
2727
"minimum-stability": "dev"
28-
}
28+
}

Diff for: phpunit.xml

+4
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
<testsuite name="cache">
2424
<directory>tests/CacheTest.php</directory>
2525
</testsuite>
26+
<testsuite name="builder">
27+
<directory>tests/QueryBuilderTest.php</directory>
28+
<directory>tests/QueryTest.php</directory>
29+
</testsuite>
2630
</testsuites>
2731
</phpunit>

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

+29-7
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,14 @@ public function orderBy($column, $direction = 'asc')
277277
* @param string $column
278278
* @param array $values
279279
* @param string $boolean
280-
* @return \Illuminate\Database\Query\Builder
280+
* @param bool $not
281+
* @return Builder
281282
*/
282-
public function whereBetween($column, array $values, $boolean = 'and')
283+
public function whereBetween($column, array $values, $boolean = 'and', $not = false)
283284
{
284285
$type = 'between';
285286

286-
$this->wheres[] = compact('column', 'type', 'boolean', 'values');
287+
$this->wheres[] = compact('column', 'type', 'boolean', 'values', 'not');
287288

288289
return $this;
289290
}
@@ -739,11 +740,32 @@ protected function compileWhereBetween($where)
739740
{
740741
extract($where);
741742

742-
return array(
743-
$column => array(
744-
'$gte' => $values[0],
745-
'$lte' => $values[1])
743+
if ($not)
744+
{
745+
return array(
746+
'$or' => array(
747+
array(
748+
$column => array(
749+
'$lte' => $values[0]
750+
)
751+
),
752+
array(
753+
$column => array(
754+
'$gte' => $values[1]
755+
)
756+
)
757+
)
746758
);
759+
}
760+
else
761+
{
762+
return array(
763+
$column => array(
764+
'$gte' => $values[0],
765+
'$lte' => $values[1]
766+
)
767+
);
768+
}
747769
}
748770

749771
protected function compileWhereRaw($where)

Diff for: tests/QueryTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public function testBetween()
103103

104104
$users = User::whereBetween('age', array(13, 23))->get();
105105
$this->assertEquals(2, count($users));
106+
107+
// testing whereNotBetween for version 4.1
108+
$users = User::whereBetween('age', array(0, 25), 'and', true)->get();
109+
$this->assertEquals(6, count($users));
106110
}
107111

108112
public function testIn()

0 commit comments

Comments
 (0)