Skip to content

Commit

Permalink
PHPORM-67 Accept operators prefixed by $ in Query\Builder::orWhere (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored and alcaeus committed Aug 22, 2023
1 parent 4514964 commit 0fb83af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- 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).
- Remove public property `Query\Builder::$paginating` [#15](https://github.com/GromNaN/laravel-mongodb-private/pull/15) by [@GromNaN](https://github.com/GromNaN).
- Remove call to deprecated `Collection::count` for `countDocuments` [#18](https://github.com/GromNaN/laravel-mongodb-private/pull/18) by [@GromNaN](https://github.com/GromNaN).
- Accept operators prefixed by `$` in `Query\Builder::orWhere` [#20](https://github.com/GromNaN/laravel-mongodb-private/pull/20) by [@GromNaN](https://github.com/GromNaN).

## [3.9.2] - 2022-09-01

Expand Down
4 changes: 2 additions & 2 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
$params = func_get_args();

// Remove the leading $ from operators.
if (func_num_args() == 3) {
if (func_num_args() >= 3) {
$operator = &$params[1];

if (Str::startsWith($operator, '$')) {
if (is_string($operator) && str_starts_with($operator, '$')) {
$operator = substr($operator, 1);
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ public static function provideQueryBuilderToMql(): iterable
fn (Builder $builder) => $builder->limit(10)->offset(5)->select('foo', 'bar'),
];

yield 'where accepts $ in operators' => [
['find' => [
['$or' => [
['foo' => ['$type' => 2]],
['foo' => ['$type' => 4]],
]],
[], // options
]],
fn (Builder $builder) => $builder
->where('foo', '$type', 2)
->orWhere('foo', '$type', 4),
];

/** @see DatabaseQueryBuilderTest::testBasicWhereNot() */
yield 'whereNot (multiple)' => [
['find' => [
Expand Down

0 comments on commit 0fb83af

Please sign in to comment.