mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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:
c86a32d745 (commitcomment-2784312)
This commit is contained in:
parent
0721d3b370
commit
133a1759a4
2 changed files with 6 additions and 1 deletions
|
@ -34,7 +34,7 @@ module ActiveRecord
|
|||
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 @@ class AssociationProxyTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue