Skip to content

Commit 0fb83af

Browse files
GromNaNalcaeus
authored andcommitted
PHPORM-67 Accept operators prefixed by $ in Query\Builder::orWhere (#20)
1 parent 4514964 commit 0fb83af

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
1212
- Throw an exception when `Query\Builder::push()` is used incorrectly [#5](https://github.com/GromNaN/laravel-mongodb-private/pull/5) by [@GromNaN](https://github.com/GromNaN).
1313
- Remove public property `Query\Builder::$paginating` [#15](https://github.com/GromNaN/laravel-mongodb-private/pull/15) by [@GromNaN](https://github.com/GromNaN).
1414
- Remove call to deprecated `Collection::count` for `countDocuments` [#18](https://github.com/GromNaN/laravel-mongodb-private/pull/18) by [@GromNaN](https://github.com/GromNaN).
15+
- Accept operators prefixed by `$` in `Query\Builder::orWhere` [#20](https://github.com/GromNaN/laravel-mongodb-private/pull/20) by [@GromNaN](https://github.com/GromNaN).
1516

1617
## [3.9.2] - 2022-09-01
1718

src/Query/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
917917
$params = func_get_args();
918918

919919
// Remove the leading $ from operators.
920-
if (func_num_args() == 3) {
920+
if (func_num_args() >= 3) {
921921
$operator = &$params[1];
922922

923-
if (Str::startsWith($operator, '$')) {
923+
if (is_string($operator) && str_starts_with($operator, '$')) {
924924
$operator = substr($operator, 1);
925925
}
926926
}

tests/Query/BuilderTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ public static function provideQueryBuilderToMql(): iterable
7676
fn (Builder $builder) => $builder->limit(10)->offset(5)->select('foo', 'bar'),
7777
];
7878

79+
yield 'where accepts $ in operators' => [
80+
['find' => [
81+
['$or' => [
82+
['foo' => ['$type' => 2]],
83+
['foo' => ['$type' => 4]],
84+
]],
85+
[], // options
86+
]],
87+
fn (Builder $builder) => $builder
88+
->where('foo', '$type', 2)
89+
->orWhere('foo', '$type', 4),
90+
];
91+
7992
/** @see DatabaseQueryBuilderTest::testBasicWhereNot() */
8093
yield 'whereNot (multiple)' => [
8194
['find' => [

0 commit comments

Comments
 (0)