Module: ActsAsRecursiveTree::Builders::Strategies::Join

Defined in:
lib/acts_as_recursive_tree/builders/strategies/join.rb

Overview

Build a relation using an INNER JOIN.

Class Method Summary collapse

Class Method Details

.apply_order(builder, relation) ⇒ Object



27
28
29
30
31
# File 'lib/acts_as_recursive_tree/builders/strategies/join.rb', line 27

def self.apply_order(builder, relation)
  return relation unless builder.ensure_ordering

  relation.order(builder.recursive_temp_table[builder.depth_column].asc)
end

.build(builder) ⇒ ActiveRecord::Relation

Builds the relation.

Parameters:

Returns:

  • (ActiveRecord::Relation)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acts_as_recursive_tree/builders/strategies/join.rb', line 15

def self.build(builder)
  final_select_mgr = builder.base_table.join(
    builder.create_select_manger.as(builder.recursive_temp_table.name)
  ).on(
    builder.base_table[builder.primary_key].eq(builder.recursive_temp_table[builder.primary_key])
  )

  relation = builder.klass.joins(final_select_mgr.join_sources)

  apply_order(builder, relation)
end