Skip to content
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

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 10, 2025

Fix PHPORM-286

Required by #3182
New fonctions from Laravel v11.38+ by laravel/framework#53679

Checklist

  • Add tests and ensure they pass

@GromNaN GromNaN added this to the 5.2 milestone Jan 10, 2025
@GromNaN GromNaN requested a review from a team as a code owner January 10, 2025 12:18
@GromNaN GromNaN requested a review from jmikola January 10, 2025 12:18
Copy link
Member

@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.

Tests look fine, but I have some questions about the Builder.

tests/QueryBuilderTest.php Outdated Show resolved Hide resolved
tests/QueryBuilderTest.php Show resolved Hide resolved
src/Query/Builder.php Show resolved Hide resolved
@@ -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'])) {
Copy link
Member

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?

Copy link
Member Author

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;

src/Query/Builder.php Show resolved Hide resolved
@GromNaN GromNaN removed the github label Jan 13, 2025
@GromNaN GromNaN requested a review from jmikola January 13, 2025 10:42
@@ -11,6 +11,8 @@ jobs:
name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"

strategy:
# Tests with Atlas fail randomly
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@GromNaN GromNaN merged commit 8829052 into mongodb:5.x Jan 13, 2025
31 of 32 checks passed
@GromNaN GromNaN deleted the PHPORM-286 branch January 13, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants