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:
parent
f1217c605d
commit
673ed05ee9
2 changed files with 4 additions and 3 deletions
|
@ -83,7 +83,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def scope
|
def scope
|
||||||
target_scope.merge(association_scope)
|
target_scope.merge!(association_scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The scope for this association.
|
# The scope for this association.
|
||||||
|
|
|
@ -955,9 +955,8 @@ module ActiveRecord
|
||||||
|
|
||||||
# Returns a <tt>Relation</tt> object for the records in this association
|
# Returns a <tt>Relation</tt> object for the records in this association
|
||||||
def scope
|
def scope
|
||||||
@association.scope
|
@scope ||= @association.scope
|
||||||
end
|
end
|
||||||
alias spawn scope
|
|
||||||
|
|
||||||
# Equivalent to <tt>Array#==</tt>. Returns +true+ if the two arrays
|
# Equivalent to <tt>Array#==</tt>. Returns +true+ if the two arrays
|
||||||
# contain the same number of elements and if each element is equal
|
# 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
|
# person.pets(true) # fetches pets from the database
|
||||||
# # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
|
# # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
|
||||||
def reload
|
def reload
|
||||||
|
@scope = nil
|
||||||
proxy_association.reload
|
proxy_association.reload
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
@ -1110,6 +1110,7 @@ module ActiveRecord
|
||||||
# person.pets # fetches pets from the database
|
# person.pets # fetches pets from the database
|
||||||
# # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
|
# # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
|
||||||
def reset
|
def reset
|
||||||
|
@scope = nil
|
||||||
proxy_association.reset
|
proxy_association.reset
|
||||||
proxy_association.reset_scope
|
proxy_association.reset_scope
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in a new issue