class Ransack::Adapters::ActiveRecord::Context
def build_joins(relation)
Checkout active_record/relation/query_methods.rb +build_joins+ for
def build_joins(relation) buckets = relation.joins_values + relation.left_outer_joins_values buckets = buckets.group_by do |join| case join when String :string_join when Hash, Symbol, Array :association_join when Polyamorous::JoinDependency, Polyamorous::JoinAssociation :stashed_join when Arel::Nodes::Join :join_node else raise 'unknown class: %s' % join.class.name end end buckets.default = [] association_joins = buckets[:association_join] stashed_association_joins = buckets[:stashed_join] join_nodes = buckets[:join_node].uniq string_joins = buckets[:string_join].map(&:strip) string_joins.uniq! join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins) alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list) join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin) join_dependency.instance_variable_set(:@alias_tracker, alias_tracker) join_nodes.each do |join| join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1 end join_dependency end