Skip to content

Commit

Permalink
PHPORM-64 Remove Query\Builder::whereAll (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored and alcaeus committed Aug 22, 2023
1 parent b9bbcdd commit 1d74dc3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- 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).
- 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).

## [3.9.2] - 2022-09-01

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ Car::where('weight', 300)

### MongoDB-specific operators

In addition to the Laravel Eloquent operators, all available MongoDB query operators can be used with `where`:

```php
User::where($fieldName, $operator, $value)->get();
```

It generates the following MongoDB filter:
```ts
{ $fieldName: { $operator: $value } }
```

**Exists**

Matches documents that have the specified field.
Expand Down
29 changes: 0 additions & 29 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,24 +530,6 @@ public function orderBy($column, $direction = 'asc')
return $this;
}

/**
* Add a "where all" clause to the query.
*
* @param string $column
* @param array $values
* @param string $boolean
* @param bool $not
* @return $this
*/
public function whereAll($column, array $values, $boolean = 'and', $not = false)
{
$type = 'all';

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

return $this;
}

/**
* @inheritdoc
* @param list{mixed, mixed}|CarbonPeriod $values
Expand Down Expand Up @@ -1044,17 +1026,6 @@ protected function compileWheres(): array
return $compiled;
}

/**
* @param array $where
* @return array
*/
protected function compileWhereAll(array $where): array
{
extract($where);

return [$column => ['$all' => array_values($values)]];
}

/**
* @param array $where
* @return array
Expand Down
16 changes: 16 additions & 0 deletions tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,22 @@ public static function provideQueryBuilderToMql(): iterable
]),
];

yield 'where all' => [
['find' => [['tags' => ['$all' => ['ssl', 'security']]], []]],
fn (Builder $builder) => $builder->where('tags', 'all', ['ssl', 'security']),
];

yield 'where all nested operators' => [
['find' => [['tags' => ['$all' => [
['$elemMatch' => ['size' => 'M', 'num' => ['$gt' => 50]]],
['$elemMatch' => ['num' => 100, 'color' => 'green']],
]]], []]],
fn (Builder $builder) => $builder->where('tags', 'all', [
['$elemMatch' => ['size' => 'M', 'num' => ['$gt' => 50]]],
['$elemMatch' => ['num' => 100, 'color' => 'green']],
]),
];

/** @see DatabaseQueryBuilderTest::testForPage() */
yield 'forPage' => [
['find' => [[], ['limit' => 20, 'skip' => 40]]],
Expand Down

0 comments on commit 1d74dc3

Please sign in to comment.