mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41754 from jhawthorn/branch_memoize_polymorphic
Simplify and memoize Preloader::Branch#polymorphic?
This commit is contained in:
commit
bcf3752247
1 changed files with 6 additions and 9 deletions
|
@ -39,9 +39,10 @@ module ActiveRecord
|
|||
|
||||
def grouped_records
|
||||
h = {}
|
||||
polymorphic_parent = !root? && parent.polymorphic?
|
||||
source_records.each do |record|
|
||||
reflection = record.class._reflect_on_association(association)
|
||||
next if polymorphic_parent? && !reflection || !record.association(association).klass
|
||||
next if polymorphic_parent && !reflection || !record.association(association).klass
|
||||
(h[reflection] ||= []) << record
|
||||
end
|
||||
h
|
||||
|
@ -53,17 +54,13 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def polymorphic_parent?
|
||||
return false if root?
|
||||
|
||||
parent.polymorphic?
|
||||
end
|
||||
|
||||
def polymorphic?
|
||||
return false if root?
|
||||
return @polymorphic if defined?(@polymorphic)
|
||||
|
||||
grouped_records.keys.any? do |reflection|
|
||||
reflection.options[:polymorphic]
|
||||
@polymorphic = source_records.any? do |record|
|
||||
reflection = record.class._reflect_on_association(association)
|
||||
reflection && reflection.options[:polymorphic]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue