-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPORM-286 Add Query::countByGroup()
and other aggregateByGroup()
functions
#3243
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look fine, but I have some questions about the Builder.
src/Query/Builder.php
Outdated
@@ -349,7 +352,7 @@ public function toMql(): array | |||
|
|||
$aggregations = blank($this->aggregate['columns']) ? [] : $this->aggregate['columns']; | |||
|
|||
if (in_array('*', $aggregations) && $function === 'count') { | |||
if (in_array('*', $aggregations) && $function === 'count' && empty($group['_id'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted that $group['_id']
is only set within the conditional for $this->groups
above. I assume this is the code path for aggregateByGroup('count')
, but it's not clear to me how aggregate()
ends up calling toMql()
. Does that happen via the call chain of get()
and getFresh()
?
Looking a few lines up (beyond the diff, as I couldn't comment there directly), I don't see $column
used after it is assigned with implode('.', $splitColumns);
. Is that dead code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, aggregateByGroup
calls aggregate
, which calls get
, which calls getFresh
, which calls toMql
.
This code is necessary, feature tested by testSubdocumentArrayAggregate
;
@@ -11,6 +11,8 @@ jobs: | |||
name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}" | |||
|
|||
strategy: | |||
# Tests with Atlas fail randomly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making an open ticket with the "Build Failure" type so you don't lose track of this. Assuming it's something that can be researched further down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix PHPORM-286
Required by #3182
New fonctions from Laravel v11.38+ by laravel/framework#53679
Checklist