提交 133a1759 编写于 作者: J Jon Leighton

Cache the association proxy object

This reimplements the behaviour of Rails 3, as I couldn't see why we
shouldn't cache the object, and @alindeman had a good use case for
caching it:

https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
上级 0721d3b3
......@@ -34,7 +34,7 @@ def reader(force_reload = false)
reload
end
CollectionProxy.new(klass, self)
@proxy ||= CollectionProxy.new(klass, self)
end
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
......
......@@ -237,6 +237,11 @@ def test_scoped_allows_conditions
assert david.projects.scope.is_a?(ActiveRecord::Relation)
assert_equal david.projects, david.projects.scope
end
test "proxy object is cached" do
david = developers(:david)
assert david.projects.equal?(david.projects)
end
end
class OverridingAssociationsTest < ActiveRecord::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册