Permalink
Browse files

remove the named scope caching mechanism on association collections. …

…this was a terrible idea because it made it very hard to get a real query when you thought you were going to, and only had effect when there was just one scope referenced, which was very confusing. 2.3 and 3.1 don't do this; take it out of 3.0.
  • Loading branch information...
1 parent 87bbf48 commit be145b233c1b2678d6b43e7f7b5e35f9dd363aa8 @willbryant committed Oct 12, 2011
@@ -108,7 +108,6 @@ def to_ary
def reset
reset_target!
- reset_named_scopes_cache!
@loaded = false
end
@@ -166,7 +165,6 @@ def delete_all
load_target
delete(@target)
reset_target!
- reset_named_scopes_cache!
end
# Calculate sum using SQL, not Enumerable
@@ -260,7 +258,6 @@ def destroy_all
load_target
destroy(@target).tap do
reset_target!
- reset_named_scopes_cache!
end
end
@@ -432,10 +429,6 @@ def method_missing(method, *args)
else
super
end
- elsif @reflection.klass.scopes[method]
- @_named_scopes_cache ||= {}
- @_named_scopes_cache[method] ||= {}
- @_named_scopes_cache[method][args] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) }
else
with_scope(construct_scope) do
if block_given?
@@ -456,10 +449,6 @@ def reset_target!
@target = Array.new
end
- def reset_named_scopes_cache!
- @_named_scopes_cache = {}
- end
-
def find_target
records =
if @reflection.options[:finder_sql]
@@ -434,28 +434,6 @@ def test_nested_named_scopes_queries_size
end
end
- def test_named_scopes_are_cached_on_associations
- post = posts(:welcome)
-
- assert_equal post.comments.containing_the_letter_e.object_id, post.comments.containing_the_letter_e.object_id
-
- post.comments.containing_the_letter_e.all # force load
- assert_no_queries { post.comments.containing_the_letter_e.all }
- end
-
- def test_named_scopes_with_arguments_are_cached_on_associations
- post = posts(:welcome)
-
- one = post.comments.limit_by(1).all
- assert_equal 1, one.size
-
- two = post.comments.limit_by(2).all
- assert_equal 2, two.size
-
- assert_no_queries { post.comments.limit_by(1).all }
- assert_no_queries { post.comments.limit_by(2).all }
- end
-
def test_named_scopes_are_reset_on_association_reload
post = posts(:welcome)

0 comments on commit be145b2

Please sign in to comment.