aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_collection.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-24 22:41:34 +0000
committerJon Leighton <j@jonathanleighton.com>2011-01-30 11:58:08 +0000
commitfdee153ff8cde2d44d751f8f961e2df13a80cd5c (patch)
tree781ea7b7c6cc536ac993519156219dac9188db95 /activerecord/lib/active_record/associations/association_collection.rb
parent5dd3dadcdd17b1bb367a127c10ae7aee4916e15c (diff)
downloadrails-fdee153ff8cde2d44d751f8f961e2df13a80cd5c.tar.gz
rails-fdee153ff8cde2d44d751f8f961e2df13a80cd5c.tar.bz2
rails-fdee153ff8cde2d44d751f8f961e2df13a80cd5c.zip
Get rid of separate reset_target! and reset_scopes_cache! methods
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb43
1 files changed, 17 insertions, 26 deletions
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]