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
Deprecate force association reload by passing true #20888
Deprecate force association reload by passing true #20888
Conversation
This is to simplify the association API, as you can call `reload` on the association proxy or the parent object to get the same result. For collection association, you can call `#reload` on association proxy to force a reload: @user.posts.reload # Instead of @user.posts(true) For singular association, you can call `#reload` on the parent object to clear its association cache then call the association method: @user.reload.profile # Instead of @user.profile(true) Passing a truthy argument to force association to reload will be removed in Rails 5.1.
Deprecate force association reload by passing true
|
This patch brings back the functionality of passing true to the association proxy. The behavior was deprecated with #20888 and scheduled for removal in Rails 5.1. The deprecation mentioned that instead of `Article.category(true)` one should use `article#reload.category`. Unfortunately the alternative does not expose the same behavior as passing true to the reader did. Specifically reloading the parent record throws unsaved changes and other caches away. Passing true only affected the association. This is problematic and there is no easy workaround. I propose to bring back the old functionality by introducing this new reader method for singular associations.
This patch brings back the functionality of passing true to the association proxy. The behavior was deprecated with #20888 and scheduled for removal in Rails 5.1. The deprecation mentioned that instead of `Article.category(true)` one should use `article#reload.category`. Unfortunately the alternative does not expose the same behavior as passing true to the reader did. Specifically reloading the parent record throws unsaved changes and other caches away. Passing true only affected the association. This is problematic and there is no easy workaround. I propose to bring back the old functionality by introducing this new reader method for singular associations.
FYI The deprecation path for singular associations will be changed in @wagenet this should address the concerns you raised about the proposed path with singular associations. |
There's a gem that reintroduces the argument-based syntax for force-reloading associations called Just a note for future travelers, since I ended up here while doing research. |
This is created in respond to #20883 and this google thread.
This is to simplify the association API, as you can call
reload
on the association proxy or the parent object to get the same result.For collection association, you can call
#reload
on association proxy to force a reload:For singular association, you can call
#reload
on the parent object to clear its association cache then call the association method:Passing a truthy argument to force association to reload will be removed in Rails 5.1.