Class: BabySqueel::JoinDependency

Inherits:
Object
  • Object
show all
Defined in:
lib/baby_squeel/join_dependency.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope, associations = []) ⇒ JoinDependency

Returns a new instance of JoinDependency.



3
4
5
6
# File 'lib/baby_squeel/join_dependency.rb', line 3

def initialize(scope, associations = [])
  @scope = scope
  @associations = associations
end

Instance Method Details

#constraintsObject

Converts an array of BabySqueel::Associations into an array of Arel join nodes.

Each association is built individually so that the correct Arel join node will be used for each individual association.



13
14
15
16
17
# File 'lib/baby_squeel/join_dependency.rb', line 13

def constraints
  @associations.each.with_index.inject([]) do |joins, (assoc, i)|
    inject @associations[0..i], joins, assoc._join
  end
end