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

Projects
None yet
6 participants
@sikachu
Member

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.

Deprecate force association reload by passing true
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

Merge pull request #20888 from sikachu/remove-support-for-force-reload
Deprecate force association reload by passing true

@rafaelfranca rafaelfranca merged commit 424b379 into rails:master Jul 15, 2015

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@sikachu sikachu deleted the sikachu:remove-support-for-force-reload branch Jul 15, 2015

@wagenet

This comment has been minimized.

Show comment
Hide comment
@wagenet

wagenet Jul 26, 2016

Contributor

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

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.

@Xosmond

This comment has been minimized.

Show comment
Hide comment
@Xosmond

Xosmond Aug 20, 2016

Im Getting this warning on this:
@clients.sales limit: 10
Am i forcing association to reload? How should i change this?

Xosmond commented on 6eae366 Aug 20, 2016

Im Getting this warning on this:
@clients.sales limit: 10
Am i forcing association to reload? How should i change this?

senny added a commit that referenced this pull request Nov 21, 2016

Introduce `reload_<association>` reader 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.

senny added a commit that referenced this pull request Nov 22, 2016

Introduce `reload_<association>` reader 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.
@senny

This comment has been minimized.

Show comment
Hide comment
@senny

senny Nov 22, 2016

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@BattleBrisket

BattleBrisket Apr 12, 2018

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.

BattleBrisket commented Apr 12, 2018

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