diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-16 11:54:46 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-16 11:54:46 -0700 |
commit | 560517689c3cf18736bcfe39c34985ddd001a2ca (patch) | |
tree | a7738c5ffa32c5d648a8abcdc88e7ca594ce16f1 /activerecord/lib/active_record/associations | |
parent | dbdaf75777d4cc16842160747ae8e0002fe271c3 (diff) | |
download | rails-560517689c3cf18736bcfe39c34985ddd001a2ca.tar.gz rails-560517689c3cf18736bcfe39c34985ddd001a2ca.tar.bz2 rails-560517689c3cf18736bcfe39c34985ddd001a2ca.zip |
cache the scope chain on the stack and eliminate `i`
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index 06b70c050e..75e4ed09a2 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -69,9 +69,11 @@ module ActiveRecord foreign_table = parent_table foreign_klass = parent.base_klass + scope_chain_iter = reflection.scope_chain.reverse_each + # The chain starts with the target table, but we want to end with it here (makes # more sense in this context), so we reverse - chain.reverse.each_with_index do |reflection, i| + chain.reverse_each do |reflection| table = tables.shift case reflection.source_macro @@ -97,7 +99,7 @@ module ActiveRecord constraint = build_constraint(reflection, table, key, foreign_table, foreign_key) - scope_chain_items = scope_chain[i].map do |item| + scope_chain_items = scope_chain_iter.next.map do |item| if item.is_a?(Relation) item else @@ -170,11 +172,6 @@ module ActiveRecord def aliased_table_name table.table_alias || table.name end - - def scope_chain - @scope_chain ||= reflection.scope_chain.reverse - end - end end end |