diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-14 13:57:17 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-14 13:57:17 -0800 |
commit | 40a015f7305affc046049ad17e16b8cc85763da7 (patch) | |
tree | 50fffce63c37d647da3ce8701a28d8d45ac10245 | |
parent | 22a1a5ac8c4631f29cfeac451c361e8da1dd2261 (diff) | |
download | rails-40a015f7305affc046049ad17e16b8cc85763da7.tar.gz rails-40a015f7305affc046049ad17e16b8cc85763da7.tar.bz2 rails-40a015f7305affc046049ad17e16b8cc85763da7.zip |
remove klass delegator
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index a6e453a3f1..42702528f0 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -3,21 +3,22 @@ module ActiveRecord class AssociationScope #:nodoc: attr_reader :association, :alias_tracker - delegate :klass, :reflection, :to => :association + delegate :reflection, :to => :association def initialize(association) @association = association - @alias_tracker = AliasTracker.new klass.connection + @alias_tracker = AliasTracker.new association.klass.connection end def scope + klass = association.klass scope = klass.unscoped scope.extending! Array(reflection.options[:extend]) owner = association.owner scope_chain = reflection.scope_chain chain = reflection.chain - add_constraints(scope, owner, scope_chain, chain) + add_constraints(scope, owner, scope_chain, chain, klass) end def join_type @@ -26,10 +27,10 @@ module ActiveRecord private - def construct_tables(chain) + def construct_tables(chain, klass) chain.map do |reflection| alias_tracker.aliased_table_for( - table_name_for(reflection), + table_name_for(reflection, klass), table_alias_for(reflection, reflection != self.reflection) ) end @@ -62,15 +63,15 @@ module ActiveRecord bind_value scope, column, value end - def add_constraints(scope, owner, scope_chain, chain) - tables = construct_tables(chain) + def add_constraints(scope, owner, scope_chain, chain, assoc_klass) + tables = construct_tables(chain, assoc_klass) chain.each_with_index do |reflection, i| table, foreign_table = tables.shift, tables.first if reflection.source_macro == :belongs_to if reflection.options[:polymorphic] - key = reflection.association_primary_key(self.klass) + key = reflection.association_primary_key(assoc_klass) else key = reflection.association_primary_key end @@ -103,7 +104,7 @@ module ActiveRecord end is_first_chain = i == 0 - klass = is_first_chain ? self.klass : reflection.klass + klass = is_first_chain ? assoc_klass : reflection.klass # Exclude the scope of the association itself, because that # was already merged in the #scope method. @@ -130,7 +131,7 @@ module ActiveRecord reflection.name end - def table_name_for(reflection) + def table_name_for(reflection, klass) if reflection == self.reflection # If this is a polymorphic belongs_to, we want to get the klass from the # association because it depends on the polymorphic_type attribute of |