diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2016-03-04 09:43:35 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2016-03-04 09:43:35 -0800 |
commit | 722319d2fe75204458ab97d5b9b1e28c7f0b1e18 (patch) | |
tree | 2038dc36da66e384f9ae4d0a51d44b37e0c0ac76 /activerecord/lib | |
parent | 999b70320b0511b5e2c8663e56a68778b1615796 (diff) | |
download | rails-722319d2fe75204458ab97d5b9b1e28c7f0b1e18.tar.gz rails-722319d2fe75204458ab97d5b9b1e28c7f0b1e18.tar.bz2 rails-722319d2fe75204458ab97d5b9b1e28c7f0b1e18.zip |
don't build the reflection chain to calculate `nested?`
We know a reflection can be considered as `nested?` if the source
reflection or the through reflection are also through reflections (since
the through reflection will also add another join table). This allows
us to avoid traversing the entire reflection tree just to calculate whether or
not there will be more join tables.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 0eff30f1db..2ca3206f20 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -138,6 +138,10 @@ module ActiveRecord # PolymorphicReflection # RuntimeReflection class AbstractReflection # :nodoc: + def through_reflection? + false + end + def table_name klass.table_name end @@ -700,6 +704,10 @@ module ActiveRecord @source_reflection_name = delegate_reflection.options[:source] end + def through_reflection? + true + end + def klass @klass ||= delegate_reflection.compute_class(class_name) end @@ -817,7 +825,7 @@ module ActiveRecord # A through association is nested if there would be more than one join table def nested? - chain.length > 2 + source_reflection.through_reflection? || through_reflection.through_reflection? end # We want to use the klass from this reflection, rather than just delegate straight to |