Skip to content

Commit

Permalink
remove more delegate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 13, 2014
1 parent e804d07 commit 7d897ab
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions activerecord/lib/active_record/associations/association_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7d897ab

Please sign in to comment.