Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

PHPORM-64 Remove Query\Builder::whereAll($field, $values) #16

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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