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

Deprecate force association reload by passing true #20888

Merged
merged 1 commit into from Jul 15, 2015

Conversation

sikachu
Copy link
Member

@sikachu sikachu commented Jul 15, 2015

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:

@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.

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.
rafaelfranca added a commit that referenced this pull request Jul 15, 2015
Deprecate force association reload by passing true
@rafaelfranca rafaelfranca merged commit 424b379 into rails:master Jul 15, 2015
@sikachu sikachu deleted the remove-support-for-force-reload branch July 15, 2015 18:18
@wagenet
Copy link
Contributor

wagenet commented Jul 26, 2016

@user.reload.profile is not the same as @user.profile(true). The former will reload the full parent object blowing away any unsaved changes, for instance. The latter only reloads the association itself. In the event where the association has more complex SQL it can be desirable to only reload the association without reloading the parent.

senny added a commit that referenced this pull request Nov 21, 2016
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.
senny added a commit that referenced this pull request Nov 22, 2016
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.
@senny
Copy link
Member

senny commented Nov 22, 2016

FYI The deprecation path for singular associations will be changed in 5.0.1. #27133 introduced a new association reader method reload_<association> to get the same behavior that passing true to would give you.

@wagenet this should address the concerns you raised about the proposed path with singular associations.

@BattleBrisket
Copy link

There's a gem that reintroduces the argument-based syntax for force-reloading associations called rails-force-reload.

Just a note for future travelers, since I ended up here while doing research.

itkrt2y added a commit to takeyuwebinc/gitfab2 that referenced this pull request Jul 3, 2018
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

Successfully merging this pull request may close these issues.

None yet

6 participants