1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

break cache if we're inside a "scoping" call. fixes #17052

For now, we don't want to take "scoping" calls in to account when
calculating cache keys for relations, so just opt-out.
This commit is contained in:
Aaron Patterson 2014-10-14 16:16:13 -07:00
parent 6bb040b557
commit b59d47d82e
2 changed files with 16 additions and 1 deletions

View file

@ -39,7 +39,12 @@ module ActiveRecord
end
def get_records
return scope.limit(1).to_a if reflection.scope_chain.any?(&:any?) || scope.eager_loading?
if reflection.scope_chain.any?(&:any?) ||
scope.eager_loading? ||
klass.current_scope
return scope.limit(1).to_a
end
conn = klass.connection
sc = reflection.association_scope_cache(conn, owner) do

View file

@ -15,6 +15,16 @@ class RelationScopingTest < ActiveRecord::TestCase
developers(:david)
end
def test_unscoped_breaks_caching
author = authors :mary
assert_nil author.first_post
post = FirstPost.unscoped do
author = authors :mary
author.reload.first_post
end
assert post
end
def test_reverse_order
assert_equal Developer.order("id DESC").to_a.reverse, Developer.order("id DESC").reverse_order
end