From fdee153ff8cde2d44d751f8f961e2df13a80cd5c Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 24 Jan 2011 22:41:34 +0000 Subject: Get rid of separate reset_target! and reset_scopes_cache! methods --- .../associations/association_collection.rb | 43 +++++++++------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 76cdc6edd5..586965bb3b 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -50,9 +50,9 @@ module ActiveRecord alias_method :to_a, :to_ary def reset - reset_target! - reset_scopes_cache! - @loaded = false + @_scopes_cache = {} + @loaded = false + @target = [] end def build(attributes = {}, &block) @@ -106,10 +106,20 @@ module ActiveRecord # # See delete for more info. def delete_all - load_target - delete(@target) - reset_target! - reset_scopes_cache! + delete(load_target).tap do + reset + loaded! + end + end + + # Destroy all the records from this association. + # + # See destroy for more info. + def destroy_all + destroy(load_target).tap do + reset + loaded! + end end # Calculate sum using SQL, not Enumerable @@ -194,17 +204,6 @@ module ActiveRecord self end - # Destroy all the records from this association. - # - # See destroy for more info. - def destroy_all - load_target - destroy(@target).tap do - reset_target! - reset_scopes_cache! - end - end - def create(attrs = {}) if attrs.is_a?(Array) attrs.collect { |attr| create(attr) } @@ -395,14 +394,6 @@ module ActiveRecord interpolate_sql(@reflection.options[:finder_sql]) end - def reset_target! - @target = [] - end - - def reset_scopes_cache! - @_scopes_cache = {} - end - def find_target records = if @reflection.options[:finder_sql] -- cgit v1.2.3