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

Feature: Eager loading in ActiveRecord::refresh() #20277

Open
chriscpty opened this issue Nov 18, 2024 · 1 comment
Open

Feature: Eager loading in ActiveRecord::refresh() #20277

chriscpty opened this issue Nov 18, 2024 · 1 comment

Comments

@chriscpty
Copy link
Contributor

chriscpty commented Nov 18, 2024

As of current, ActiveRecord::refresh() and BaseActiveRecord::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 to refresh:

public function refresh ($with = [])

The implementation in ActiveRecord uses the corresponding model's ActiveQuery anyway, so it might as well call ->with(...$with) on it in the process.

Q A
Yii version dev-master
PHP version 8.1
Operating system Debian 12

I'd be happy to implement this, but want to be sure this makes sense and I haven't missed anything relevant before :)

@samdark
Copy link
Member

samdark commented Nov 18, 2024

I find it interesting. @yiisoft/yii2, @yiisoft/reviewers thoughts?

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

No branches or pull requests

2 participants