Permalink
Browse files

remove more delegate methods

  • Loading branch information...
1 parent e804d07 commit 7d897abeccb8533d770ac1d0768eca20ec2f3971 @tenderlove tenderlove committed Feb 13, 2014
Showing with 9 additions and 7 deletions.
  1. +9 −7 activerecord/lib/active_record/associations/association_scope.rb
@@ -3,8 +3,8 @@ module Associations
class AssociationScope #:nodoc:
attr_reader :association, :alias_tracker
- delegate :klass, :owner, :reflection, :to => :association
- delegate :chain, :scope_chain, :options, :to => :reflection
+ delegate :klass, :reflection, :to => :association
+ delegate :chain, :scope_chain, :to => :reflection
def initialize(association)
@association = association
@@ -13,8 +13,10 @@ def initialize(association)
def scope
scope = klass.unscoped
- scope.extending! Array(options[:extend])
- add_constraints(scope)
+ scope.extending! Array(reflection.options[:extend])
+
+ owner = association.owner
+ add_constraints(scope, owner)
end
def join_type
@@ -59,7 +61,7 @@ def bind(scope, table_name, column_name, value)
bind_value scope, column, value
end
- def add_constraints(scope)
+ def add_constraints(scope, owner)
tables = construct_tables
chain.each_with_index do |reflection, i|
@@ -105,7 +107,7 @@ def add_constraints(scope)
# Exclude the scope of the association itself, because that
# was already merged in the #scope method.
scope_chain[i].each do |scope_chain_item|
- item = eval_scope(klass, scope_chain_item)
+ item = eval_scope(klass, scope_chain_item, owner)
if scope_chain_item == self.reflection.scope
scope.merge! item.except(:where, :includes, :bind)
@@ -138,7 +140,7 @@ def table_name_for(reflection)
end
end
- def eval_scope(klass, scope)
+ def eval_scope(klass, scope, owner)
if scope.is_a?(Relation)
scope
else

0 comments on commit 7d897ab

Please sign in to comment.