I agree that having a single API is nice. However, I feel like it would be 
confusing if user want to reload the has_one association, as they have to 
reload the original record instead of just passing true.

Consider this scenario:

# User has_one :profile, Profile belongs_to :user
> user = User.first
> user.profile #=> #<Profile id: 1, user_id: 1>

> Profile.find(1).update_attrbutes!(user_id: 2)

> Profile.find(1) #=> #<Profile id: 1, user_id: 2>
> user.profile #=> #<Profile id: 1, user_id: 1>

> user.profile.reload #=> #<Profile id: 1, user_id: 2> # << ?!
> user.profile(true) #=> nil
You can see that by removing the support for passing an argument to force 
reload makes it more confusing as you get a stale record. The workaround is to 
call user.reload.profile instead.

If you think that workaround is good enough, I don’t mind submit another PR to 
remove the support to simplify the API, though.

-Prem


On July 15, 2015 at 9:08:04 AM, DHH ([email protected]) wrote:

I'd prefer to see us move to a single API, and IMO the trade-offs for #reload 
alone fits the bill. There's no contract saying that a singular object from 
has_one/belongs_to and a collection like has_many has to behave the same. In 
fact, I think it'd be strange to think that it should. A single string and an 
array of strings do not behave the same.

So project.documents.reload.first makes perfect sense to me as reloading the 
documents collection, then grabbing the first one. projects.owner.reload.name 
makes sense to me as reloading the owner record itself, then fetching the name 
(if we don't already return self from Record#reload, we should).
--
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to