instance method
build_join_buckets
Ruby on Rails edge
Since v6.1.7.10 Private — implementation detail, not part of the public APISignature
build_join_buckets()
No documentation comment.
Source
# File activerecord/lib/active_record/relation/query_methods.rb, line 2123
def build_join_buckets
leading_joins = []
join_nodes = []
unless left_outer_joins_values.empty?
left_values = classify_join_values(left_outer_joins_values)
raise ArgumentError, "only Hash, Symbol and Array are allowed" unless left_values.nodes.empty?
left_values.cte_names.each do |cte_name|
join_nodes << build_with_join_node(cte_name, Arel::Nodes::OuterJoin)
end
left_joins = left_values.association_names
stashed_left_joins = left_values.join_dependencies
if joins_values.empty?
return JoinBuckets.new(leading_joins, left_joins, stashed_left_joins, join_nodes, Arel::Nodes::OuterJoin)
end
stashed_outer_join = construct_join_dependency(left_joins, Arel::Nodes::OuterJoin)
end
joins = joins_values.dup
if joins.last.is_a?(ActiveRecord::Associations::JoinDependency)
stashed_eager_load = joins.pop if joins.last.base_klass == model
end
joins.each_with_index do |join, i|
joins[i] = Arel::Nodes::StringJoin.new(Arel.sql(join.strip)) if join.is_a?(String)
end
while joins.first.is_a?(Arel::Nodes::Join)
join_node = joins.shift
if !join_node.is_a?(Arel::Nodes::LeadingJoin) && (stashed_eager_load || stashed_left_joins)
join_nodes << join_node
else
leading_joins << join_node
end
end
values = classify_join_values(joins)
values.cte_names.each do |cte_name|
join_nodes << build_with_join_node(cte_name)
end
values.nodes.each do |node|
raise "unknown class: %s" % node.class.name unless node.is_a?(Arel::Nodes::Join)
join_nodes << node
end
named_joins = values.association_names
stashed_inner_joins = values.join_dependencies
# The join dependencies rooted at the model never depend on another join,
# while the ones merged in from a relation of another model join to the
# tables they bring in, so those come first.
stashed_joins = [
stashed_eager_load, stashed_outer_join, *stashed_inner_joins, *stashed_left_joins
].compact
JoinBuckets.new(leading_joins, named_joins, stashed_joins, join_nodes, Arel::Nodes::InnerJoin)
end
Defined in activerecord/lib/active_record/relation/query_methods.rb line 2123
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::QueryMethods