-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Feature: Eager loading in ActiveRecord::refresh() #20277
Comments
I find it interesting. @yiisoft/yii2, @yiisoft/reviewers thoughts? |
This would be great, but if we want to add this in Yii 2 we need to do this with method arguments discovery, like Symfony does sometimes (for BC). |
What's "method arguments discovery"? |
Sorry, my term :P I mean this func_get_args() inside to allow flexibility. |
I don't think I see why that'd be necessary instead of just having the The only case of breaking I could see (that would happen afterwards though) is if a user overrides |
Adding argument to refresh(), even optional one, will break user's apps that extend this method. |
Just tested it and yeah, you are right - I misremembered whether PHP can deal with arguments being missing in overrides :D func_get_args() it is then |
Should go into 2.2, if implemented. |
2.2 may break compatibility. |
As of current,
ActiveRecord::refresh()
andBaseActiveRecord::refresh()
only refresh the record itself and lose all relations. This is the expected behaviour, but if you then need to iterate over nested relations afterwards, lazy loading them leads to an excessive amount of DB queries.My proposal would thus be to add an optional parameter
with
torefresh
:public function refresh ($with = [])
The implementation in
ActiveRecord
uses the corresponding model'sActiveQuery
anyway, so it might as well call->with(...$with)
on it in the process.I'd be happy to implement this, but want to be sure this makes sense and I haven't missed anything relevant before :)
The text was updated successfully, but these errors were encountered: