Class: ActiveRecord::Associations::AssociationScope

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

Overview

:nodoc:

Defined Under Namespace

Classes: ReflectionProxy

Constant Summary collapse

INSTANCE =
create

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_transformation) ⇒ AssociationScope

Returns a new instance of AssociationScope.



15
16
17
# File 'lib/active_record/associations/association_scope.rb', line 15

def initialize(value_transformation)
  @value_transformation = value_transformation
end

Class Method Details

.create(&block) ⇒ Object



10
11
12
13
# File 'lib/active_record/associations/association_scope.rb', line 10

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

.get_bind_values(owner, chain) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_record/associations/association_scope.rb', line 32

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.polymorphic_name
  end

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

.scope(association) ⇒ Object



6
7
8
# File 'lib/active_record/associations/association_scope.rb', line 6

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

Instance Method Details

#scope(association) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/associations/association_scope.rb', line 21

def scope(association)
  klass = association.klass
  reflection = association.reflection
  scope = klass.unscoped
  owner = association.owner
  chain = get_chain(reflection, association, scope.alias_tracker)

  scope.extending! reflection.extensions
  add_constraints(scope, owner, chain)
end