Class: ActiveRecord::Associations::AssociationScope

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/associations/association_scope.rb

Overview

:nodoc:

Defined Under Namespace

Classes: BindSubstitution

Constant Summary collapse

INSTANCE =
create

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bind_substitution) ⇒ AssociationScope

Returns a new instance of AssociationScope.


25
26
27
# File 'activerecord/lib/active_record/associations/association_scope.rb', line 25

def initialize(bind_substitution)
  @bind_substitution = bind_substitution
end

Class Method Details

.create(&block) ⇒ Object


20
21
22
23
# File 'activerecord/lib/active_record/associations/association_scope.rb', line 20

def self.create(&block)
  block = block ? block : lambda { |val| val }
  new BindSubstitution.new(block)
end

.get_bind_values(owner, chain) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'activerecord/lib/active_record/associations/association_scope.rb', line 46

def self.get_bind_values(owner, chain)
  binds = []
  last_reflection = chain.last

  binds << last_reflection.join_id_for(owner)
  if last_reflection.type
    binds << owner.class.base_class.name
  end

  chain.each_cons(2).each do |reflection, next_reflection|
    if reflection.type
      binds << next_reflection.klass.base_class.name
    end
  end
  binds
end

.scope(association, connection) ⇒ Object


4
5
6
# File 'activerecord/lib/active_record/associations/association_scope.rb', line 4

def self.scope(association, connection)
  INSTANCE.scope association, connection
end

Instance Method Details

#join_typeObject


42
43
44
# File 'activerecord/lib/active_record/associations/association_scope.rb', line 42

def join_type
  Arel::Nodes::InnerJoin
end

#scope(association, connection) ⇒ Object


31
32
33
34
35
36
37
38
39
40
# File 'activerecord/lib/active_record/associations/association_scope.rb', line 31

def scope(association, connection)
  klass         = association.klass
  reflection    = association.reflection
  scope         = klass.unscoped
  owner         = association.owner
  alias_tracker = AliasTracker.empty connection

  scope.extending! Array(reflection.options[:extend])
  add_constraints(scope, owner, klass, reflection, alias_tracker)
end