Class: BabySqueel::Join

Inherits:
Object
  • Object
show all
Includes:
Polyamorous::TreeNode
Defined in:
lib/baby_squeel/join.rb

Overview

This is the thing that gets added to Active Record’s joins_values. By including Polyamorous::TreeNode, when this instance is found when traversing joins in ActiveRecord::Associations::JoinDependency::walk_tree, Join#add_to_tree will be called.

Instance Method Summary collapse

Constructor Details

#initialize(associations) ⇒ Join

Returns a new instance of Join.



9
10
11
# File 'lib/baby_squeel/join.rb', line 9

def initialize(associations)
  @associations = associations
end

Instance Method Details

#add_to_tree(hash) ⇒ Object

Each individual association object knows how to build a Polyamorous::Join. Those joins will be added to the hash incrementally.



16
17
18
19
20
# File 'lib/baby_squeel/join.rb', line 16

def add_to_tree(hash)
  @associations.inject(hash) do |acc, assoc|
    assoc.add_to_tree(acc)
  end
end