diff options
author | Kelsey Schlarman <kschlarman@gmail.com> | 2014-01-21 18:19:51 -0800 |
---|---|---|
committer | Kelsey Schlarman <kschlarman@gmail.com> | 2014-01-21 18:24:28 -0800 |
commit | 43675f014c8d0913650823a5a3e92c8555a3caed (patch) | |
tree | 62d9b77acad1b82d28906983cea75360b7a70041 /activerecord/lib/active_record | |
parent | a4ce0659433cc83c5b098c4e900b5214787e99b0 (diff) | |
download | rails-43675f014c8d0913650823a5a3e92c8555a3caed.tar.gz rails-43675f014c8d0913650823a5a3e92c8555a3caed.tar.bz2 rails-43675f014c8d0913650823a5a3e92c8555a3caed.zip |
Calling reset on a collection association should unload the assocation
Need to define #reset on CollectionProxy.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index a67b834a80..08bc409816 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -1004,6 +1004,27 @@ module ActiveRecord proxy_association.reload self end + + # Unloads the association + # + # class Person < ActiveRecord::Base + # has_many :pets + # end + # + # person.pets # fetches pets from the database + # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] + # + # person.pets # uses the pets cache + # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] + # + # person.pets.reset # clears the pets cache + # + # person.pets # fetches pets from the database + # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] + def reset + proxy_association.reset + proxy_association.reset_scope + end end end end |