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

Cache target scope for collection proxy

This commit is contained in:
Ryuta Kamizono 2016-07-19 01:18:08 +09:00
parent f1217c605d
commit 673ed05ee9
2 changed files with 4 additions and 3 deletions

View file

@ -83,7 +83,7 @@ module ActiveRecord
end
def scope
target_scope.merge(association_scope)
target_scope.merge!(association_scope)
end
# The scope for this association.

View file

@ -955,9 +955,8 @@ module ActiveRecord
# Returns a <tt>Relation</tt> object for the records in this association
def scope
@association.scope
@scope ||= @association.scope
end
alias spawn scope
# Equivalent to <tt>Array#==</tt>. Returns +true+ if the two arrays
# contain the same number of elements and if each element is equal
@ -1089,6 +1088,7 @@ module ActiveRecord
# person.pets(true) # fetches pets from the database
# # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
def reload
@scope = nil
proxy_association.reload
self
end
@ -1110,6 +1110,7 @@ module ActiveRecord
# person.pets # fetches pets from the database
# # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
def reset
@scope = nil
proxy_association.reset
proxy_association.reset_scope
self