提交 9f37f335 编写于 作者: J Jeremy Kemper

Merge pull request #5718 from benedikt/master

Removes caching from ActiveRecord::Core::ClassMethods#relation
......@@ -137,12 +137,12 @@ def arel_engine
private
def relation #:nodoc:
@relation ||= Relation.new(self, arel_table)
relation = Relation.new(self, arel_table)
if finder_needs_type_condition?
@relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name)
relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name)
else
@relation
relation
end
end
end
......@@ -351,7 +351,6 @@ def init_internals
@attributes[pk] = nil unless @attributes.key?(pk)
@relation = nil
@aggregation_cache = {}
@association_cache = {}
@attributes_cache = {}
......
......@@ -35,7 +35,7 @@ def scoped(options = nil)
if current_scope
current_scope.clone
else
scope = relation.clone
scope = relation
scope.default_scoped = true
scope
end
......@@ -49,7 +49,7 @@ def scope_attributes # :nodoc:
if current_scope
current_scope.scope_for_create
else
scope = relation.clone
scope = relation
scope.default_scoped = true
scope.scope_for_create
end
......
......@@ -1174,6 +1174,12 @@ def test_deep_including_through_habtm
assert_equal Comment.find(1), Comment.preload(:post => :comments).scoping { Comment.find(1) }
end
test "circular preload does not modify unscoped" do
expected = FirstPost.unscoped.find(2)
FirstPost.preload(:comments => :first_post).find(1)
assert_equal expected, FirstPost.unscoped.find(2)
end
test "preload ignores the scoping" do
assert_equal(
Comment.find(1).post,
......
......@@ -9,6 +9,8 @@ class Comment < ActiveRecord::Base
belongs_to :post, :counter_cache => true
has_many :ratings
belongs_to :first_post, :foreign_key => :post_id
has_many :children, :class_name => 'Comment', :foreign_key => :parent_id
belongs_to :parent, :class_name => 'Comment', :counter_cache => :children_count
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册