-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Double query when using $with in model, and SerializesModels trait #55546
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
Comments
So maybe we should ignore the Or maybe we can change |
I don't know what is the best strategy, but I will go with change from load() to loadMissing(). We also need to test, if this is happening when serializing a collection ... |
Reproduces laravel issue: laravel/framework#55546
I created a repo that reproduces this error: https://github.com/AndrewMast/laravel-testing/tree/issue-55546 (see diff). Steps to reproduce after cloning:
As brought up in the issue, these queries are run: select * from "users" where "users"."id" = 1 limit 1
select * from "countries" where "countries"."id" in (1)
select * from "countries" where "countries"."id" in (1) When changing select * from "users" where "users"."id" = 1 limit 1
select * from "countries" where "countries"."id" in (1) I plan on opening a PR to fix this issue. |
@alexmontoanelli This should be fixed with #55547 being merged. |
Should be officially fixed with v12.11.0. |
Laravel Version
12.x
PHP Version
8.3
Database Driver & Version
No response
Description
If you have a model, with the 'public $with' attribute to autoEagerLoad relationships,
when, unserializing a model in (queue worker, after a job pickup), the Model itself load the relationship ($with attribute), and if the relationship was loaded before the job dispatched, the Trait SerializesAndRestoresModelIdentifiers will load that relationship again.
In my investigations, the SerializesAndRestoresModelIdentifiers::110, is the issue where
he tries to load the relation.
If he use loadMissing, the behavior is OK, no relation already loaded will be loaded.
Steps To Reproduce
The text was updated successfully, but these errors were encountered: