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

Conversation

GromNaN
Copy link
Owner

@GromNaN GromNaN commented Jul 19, 2023

Fix PHPORM-64

Use where($field, 'all', $values) instead.

Introduced in 2017 without explaining the motivation mongodb/laravel-mongodb#1320

@GromNaN GromNaN requested review from jmikola and alcaeus July 19, 2023 16:44
@GromNaN GromNaN requested a review from jmikola July 19, 2023 19:59
@GromNaN GromNaN force-pushed the PHPORM-64 branch 2 times, most recently from 9498ce8 to 32cf6ae Compare July 25, 2023 07:21
Copy link
Collaborator

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a suggestion to improve docs.

README.md Outdated
@@ -631,6 +631,17 @@ $bars = Bar::raw(function ($collection) {
});
```

**Other operators**

You can use any [MongoDB query operator](https://www.mongodb.com/docs/manual/reference/operator/query/#query-selectors) with the `where` function:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the resulting query from this call for the sake of completeness.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for this example? If I add the generated BSON query to all the examples, the README will become very very long. Or I can use a collapsible section.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can just be added for this example. It's unique in that it's showing you how to use an arbitrary query operator, so the goal should be communicating what you said in this comment:

Basically, where($field, $operator, $values) generates { $field: { $operator: $values } }

That said, I think the $all with $elemMatch example would be better suited for a test case. That was my intention in this comment.

For a documentation example, I think the current test case works better:

$builder->where('tags', 'all', ['ssl', 'security'])

My reasoning:

  • The test case lets us know that the more complex query is possible using this API
  • The documentation would do well to toe the line between explaining to users how to run an arbitrary query with where() while also not overwhelming or distracting them with a very niche query

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the test and revisited the doc. There is already an example with $all.
All operator listed in Builder::$operators are supported.

Copy link
Collaborator

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the current test case moved to a docs example (and resulting query shown), and the $all with $elemMatch example moved to the test.

README.md Outdated
@@ -631,6 +631,17 @@ $bars = Bar::raw(function ($collection) {
});
```

**Other operators**

You can use any [MongoDB query operator](https://www.mongodb.com/docs/manual/reference/operator/query/#query-selectors) with the `where` function:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can just be added for this example. It's unique in that it's showing you how to use an arbitrary query operator, so the goal should be communicating what you said in this comment:

Basically, where($field, $operator, $values) generates { $field: { $operator: $values } }

That said, I think the $all with $elemMatch example would be better suited for a test case. That was my intention in this comment.

For a documentation example, I think the current test case works better:

$builder->where('tags', 'all', ['ssl', 'security'])

My reasoning:

  • The test case lets us know that the more complex query is possible using this API
  • The documentation would do well to toe the line between explaining to users how to run an arbitrary query with where() while also not overwhelming or distracting them with a very niche query

@GromNaN GromNaN force-pushed the PHPORM-64 branch 3 times, most recently from b6194e6 to 2d89bbf Compare July 26, 2023 08:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants