From 43675f014c8d0913650823a5a3e92c8555a3caed Mon Sep 17 00:00:00 2001 From: Kelsey Schlarman Date: Tue, 21 Jan 2014 18:19:51 -0800 Subject: Calling reset on a collection association should unload the assocation Need to define #reset on CollectionProxy. --- .../active_record/associations/collection_proxy.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/lib/active_record') 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 + # # => [#] + # + # person.pets # uses the pets cache + # # => [#] + # + # person.pets.reset # clears the pets cache + # + # person.pets # fetches pets from the database + # # => [#] + def reset + proxy_association.reset + proxy_association.reset_scope + end end end end -- cgit v1.2.3