diff options
author | eileencodes <eileencodes@gmail.com> | 2014-12-02 19:03:25 -0500 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2015-01-02 17:15:31 -0500 |
commit | f6729309a06f40b32e52f8ee8143d1b1da412597 (patch) | |
tree | 2832d15bb4b63e259a296ae713f9ef58d07a510c /activerecord/lib | |
parent | e9684d6c8849767ad38cb3cc76cb628252a67ed6 (diff) | |
download | rails-f6729309a06f40b32e52f8ee8143d1b1da412597.tar.gz rails-f6729309a06f40b32e52f8ee8143d1b1da412597.tar.bz2 rails-f6729309a06f40b32e52f8ee8143d1b1da412597.zip |
Assign the `#alias_name` to each reflection
This makes the `#alias_name` more functional.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 23 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 10 |
2 files changed, 15 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index 949ba75b1b..0fdb3737fd 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -114,24 +114,25 @@ module ActiveRecord end class ReflectionProxy < SimpleDelegator - attr_accessor :next + attr_accessor :next, :alias_name - def alias_name(name, alias_tracker) - @alias ||= begin - alias_name = "#{plural_name}_#{name}" - alias_tracker.aliased_table_for(table_name, alias_name) - end + def alias_candidate(name) + "#{plural_name}_#{name}" end end def get_chain(refl, association, tracker) name = refl.name runtime_reflection = ActiveRecord::Reflection::RuntimeReflection.new(refl, association) - runtime_reflection.alias_name(name, tracker) + alias_name = tracker.aliased_table_for(runtime_reflection.table_name, runtime_reflection.alias_candidate(name)) + runtime_reflection.alias_name = alias_name prev = runtime_reflection refl.chain.drop(1).each { |reflection| proxy = ReflectionProxy.new(reflection) - proxy.alias_name(name, tracker) + + alias_name = tracker.aliased_table_for(proxy.table_name, proxy.alias_candidate(name)) + proxy.alias_name = alias_name + prev.next = proxy prev = proxy } @@ -140,17 +141,17 @@ module ActiveRecord def add_constraints(scope, owner, assoc_klass, refl, tracker, chain_head, chain_tail) owner_reflection = chain_tail - table = owner_reflection.alias_name(refl.name, tracker) + table = owner_reflection.alias_name scope = last_chain_scope(scope, table, owner_reflection, owner, tracker, assoc_klass) reflection = chain_head loop do break unless reflection - table = reflection.alias_name(refl.name, tracker) + table = reflection.alias_name unless reflection == chain_tail next_reflection = reflection.next - foreign_table = next_reflection.alias_name(refl.name, tracker) + foreign_table = next_reflection.alias_name scope = next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_table, next_reflection) end diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index ea469f881c..79c6504a18 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -936,7 +936,7 @@ module ActiveRecord end class RuntimeReflection < PolymorphicReflection - attr_accessor :next + attr_accessor :next, :alias_name def initialize(reflection, association) @reflection = reflection @@ -959,12 +959,8 @@ module ActiveRecord @reflection.source_type_info end - def alias_name(name, alias_tracker) - @alias ||= begin - alias_name = "#{plural_name}_#{name}_join" - table_name = klass.table_name - alias_tracker.aliased_table_for(table_name, alias_name) - end + def alias_candidate(name) + "#{plural_name}_#{name}_join" end end end |