Skip to content

[11.x] Merge in eager loads from nested where queries#54455

Merged
taylorotwell merged 3 commits into
laravel:11.xfrom
ollieread:feat/allow-relationships-in-nested-clauses
Feb 5, 2025
Merged

[11.x] Merge in eager loads from nested where queries#54455
taylorotwell merged 3 commits into
laravel:11.xfrom
ollieread:feat/allow-relationships-in-nested-clauses

Conversation

@ollieread
Copy link
Copy Markdown
Contributor

This PR merges in any eager loads from nested where clauses, so that withWhereHas can be used within a nested where.

@ollieread ollieread changed the title Merge in eager loads from nested where queries [11.x] Merge in eager loads from nested where queries Feb 3, 2025
@taylorotwell taylorotwell merged commit e4547b4 into laravel:11.x Feb 5, 2025
@AndreaBellini23
Copy link
Copy Markdown

AndreaBellini23 commented Feb 21, 2025

After updating to v11.42.0, which implements these changes, a query like

return $query->withWhereHas('model:column', function ($query) {
                            // something ;
                        });

throws a RelationNotFoundException "Call to undefined relationship [model:column] on model [App\Models{model}]
But if I remove the ":column" in withWhereHas, I don't get any exception.

I'm not sure if now this a correct behaviour, so I'm writing this comment before creating an issue.

@ollieread
Copy link
Copy Markdown
Contributor Author

After updating to v11.42.0, which implements these changes, a query like

return $query->withWhereHas('model:column', function ($query) {
                            // something ;
                        });

throws a RelationNotFoundException "Call to undefined relationship [model:column] on model [App\Models{model}] But if I remove the ":column" in withWhere has, I don't get any exception.

I'm not sure if now this a correct behaviour, so I'm writing this comment before creating an issue.

I'll look into this today for you. It may be worth creating an issue anyway, but link to this PR and tag me in it. I'll see if I can figure out what's happening.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants