Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get rid of separate reset_target! and reset_scopes_cache! methods

  • Loading branch information...
commit fdee153ff8cde2d44d751f8f961e2df13a80cd5c 1 parent 5dd3dad
@jonleighton jonleighton authored
Showing with 17 additions and 26 deletions.
  1. +17 −26 activerecord/lib/active_record/associations/association_collection.rb
View
43 activerecord/lib/active_record/associations/association_collection.rb
@@ -50,9 +50,9 @@ def to_ary
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 @@ def transaction(*args)
#
# 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 @@ def clear
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 @@ def custom_finder_sql
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]
Please sign in to comment.
Something went wrong with that request. Please try again.