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

PR #53209 changes aggregations with group-by #53581

Closed
rikvdh opened this issue Nov 19, 2024 · 3 comments
Closed

PR #53209 changes aggregations with group-by #53581

rikvdh opened this issue Nov 19, 2024 · 3 comments

Comments

@rikvdh
Copy link
Contributor

rikvdh commented Nov 19, 2024

Laravel Version

11.33.0

PHP Version

8.3.14

Database Driver & Version

MariaDB

Description

The behavior is changed in PR #53209. I've built queries in my application which I need further on. But now the behavior changed for aggregate-functions like: min(...), max(...).

When having joins and aggregations with custom selects from joined tables I've seen other issues producing invalid SQL queries due to the subquery existing and columns not existing outside the subquery. But I cannot make an isolated testset and the query is too big.

Steps To Reproduce

in 11.32.0:

Model::groupBy('field')->min('column');

returns int.

in 11.33.0:

Model::groupBy('field')->min('column');

returns collection.

@rikvdh
Copy link
Contributor Author

rikvdh commented Nov 19, 2024

Ok, I've made a testcase which now is broken in v11.33.0:

Returns::groupBy('orders.locale')
            ->join('orders', 'orders.id', 'order_id')
            ->having('nreturns', '>', 10)
            ->selectRaw('orders.locale,returns.created_at,count(distinct returns.id) as nreturns')
            ->min('returns.created_at')

The having clause seems to break the query, this makes the 'orders.locale' invalid outside the subquery.

@crynobone
Copy link
Member

@rikvdh Can you create a simple TestCase that would cover this usage?

@taylorotwell
Copy link
Member

Reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants