Introduce reload_<association>
reader for singular associations.
#27133
Conversation
I thought we had agreed on using #reload_category or another dynamic method? I don't like using a mystery boolean like that. It's a terrible API (even if I originally designed it!). |
@dhh that is what Yves is proposing in this PR. |
Ha! I should have read the diff, not the description. Silly me. |
Sounds very sad. |
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.
I see the deprecation warning in the We should probably change that wording now :) |
@kaspth I'm on it. I guess for |
|
Introduce `reload_<association>` reader for singular associations. This backport contains modifications to the deprecation warning. This will smoothen the upgrade path for users that were relying on force reloading singular associations.
Backported with ecb394a |
Anyone successfully using the old recommendation is fine. It's only insufficient for a narrow use case. (Do we want to recommend both? Or is that just confusing?) |
@matthewd I don't think it's necessary. Honestly now that we have |
Summary
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)
oneshould use
article#reload.category
. Unfortunately the alternative doesnot 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.
Implications
We started to issue deprecation warnings for this since 5.0.0. If this is merged, I think we should backport the patch to
5-0-stable
and update the deprecation warning accordingly.