Skip to content

Commit 1d74dc3

Browse files
GromNaNalcaeus
authored andcommitted
PHPORM-64 Remove Query\Builder::whereAll (#16)
1 parent b9bbcdd commit 1d74dc3

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
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).
1515
- Accept operators prefixed by `$` in `Query\Builder::orWhere` [#20](https://github.com/GromNaN/laravel-mongodb-private/pull/20) by [@GromNaN](https://github.com/GromNaN).
16+
- Remove `Query\Builder::whereAll($column, $values)`. Use `Query\Builder::where($column, 'all', $values)` instead. [#16](https://github.com/GromNaN/laravel-mongodb-private/pull/16) by [@GromNaN](https://github.com/GromNaN).
1617

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

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,17 @@ Car::where('weight', 300)
483483

484484
### MongoDB-specific operators
485485

486+
In addition to the Laravel Eloquent operators, all available MongoDB query operators can be used with `where`:
487+
488+
```php
489+
User::where($fieldName, $operator, $value)->get();
490+
```
491+
492+
It generates the following MongoDB filter:
493+
```ts
494+
{ $fieldName: { $operator: $value } }
495+
```
496+
486497
**Exists**
487498

488499
Matches documents that have the specified field.

src/Query/Builder.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -530,24 +530,6 @@ public function orderBy($column, $direction = 'asc')
530530
return $this;
531531
}
532532

533-
/**
534-
* Add a "where all" clause to the query.
535-
*
536-
* @param string $column
537-
* @param array $values
538-
* @param string $boolean
539-
* @param bool $not
540-
* @return $this
541-
*/
542-
public function whereAll($column, array $values, $boolean = 'and', $not = false)
543-
{
544-
$type = 'all';
545-
546-
$this->wheres[] = compact('column', 'type', 'boolean', 'values', 'not');
547-
548-
return $this;
549-
}
550-
551533
/**
552534
* @inheritdoc
553535
* @param list{mixed, mixed}|CarbonPeriod $values
@@ -1044,17 +1026,6 @@ protected function compileWheres(): array
10441026
return $compiled;
10451027
}
10461028

1047-
/**
1048-
* @param array $where
1049-
* @return array
1050-
*/
1051-
protected function compileWhereAll(array $where): array
1052-
{
1053-
extract($where);
1054-
1055-
return [$column => ['$all' => array_values($values)]];
1056-
}
1057-
10581029
/**
10591030
* @param array $where
10601031
* @return array

tests/Query/BuilderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ public static function provideQueryBuilderToMql(): iterable
333333
]),
334334
];
335335

336+
yield 'where all' => [
337+
['find' => [['tags' => ['$all' => ['ssl', 'security']]], []]],
338+
fn (Builder $builder) => $builder->where('tags', 'all', ['ssl', 'security']),
339+
];
340+
341+
yield 'where all nested operators' => [
342+
['find' => [['tags' => ['$all' => [
343+
['$elemMatch' => ['size' => 'M', 'num' => ['$gt' => 50]]],
344+
['$elemMatch' => ['num' => 100, 'color' => 'green']],
345+
]]], []]],
346+
fn (Builder $builder) => $builder->where('tags', 'all', [
347+
['$elemMatch' => ['size' => 'M', 'num' => ['$gt' => 50]]],
348+
['$elemMatch' => ['num' => 100, 'color' => 'green']],
349+
]),
350+
];
351+
336352
/** @see DatabaseQueryBuilderTest::testForPage() */
337353
yield 'forPage' => [
338354
['find' => [[], ['limit' => 20, 'skip' => 40]]],

0 commit comments

Comments
 (0)