Class: ActiveRecord::HierarchicalQuery::JoinBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/hierarchical_query/join_builder.rb

Defined Under Namespace

Classes: SubqueryAlias

Instance Method Summary collapse

Constructor Details

#initialize(query, join_to, subquery_alias, options = {}) ⇒ JoinBuilder

Returns a new instance of JoinBuilder.

Parameters:



10
11
12
13
14
15
16
# File 'lib/active_record/hierarchical_query/join_builder.rb', line 10

def initialize(query, join_to, subquery_alias, options = {})
  @query = query
  @builder = CTE::QueryBuilder.new(query, options: options)
  @relation = join_to
  @alias = Arel::Table.new(subquery_alias)
  @options = options
end

Instance Method Details

#buildObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_record/hierarchical_query/join_builder.rb', line 18

def build
  relation = @relation

  # add ordering by "__order_column"
  relation.order_values += order_columns if ordered?

  relation = relation.joins(joined_arel_node)

  return relation unless ActiveRecord.version < Gem::Version.new("5.2")

  relation.bind_values += bind_values

  relation
end