Skip to content

Commit

Permalink
remove the named scope caching mechanism on association collections. …
Browse files Browse the repository at this point in the history
…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
willbryant committed Oct 12, 2011
1 parent 87bbf48 commit be145b2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def to_ary

def reset
reset_target!
reset_named_scopes_cache!
@loaded = false
end

Expand Down Expand Up @@ -166,7 +165,6 @@ def delete_all
load_target
delete(@target)
reset_target!
reset_named_scopes_cache!
end

# Calculate sum using SQL, not Enumerable
Expand Down Expand Up @@ -260,7 +258,6 @@ def destroy_all
load_target
destroy(@target).tap do
reset_target!
reset_named_scopes_cache!
end
end

Expand Down Expand Up @@ -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?
Expand All @@ -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]
Expand Down
22 changes: 0 additions & 22 deletions activerecord/test/cases/named_scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit be145b2

Please sign in to comment.