module Babik::QuerySet::Join

Join between two tables

Join between two tables

Public Class Methods

new_from_association(association, association_position, origin_table_alias, join = LeftJoin) click to toggle source

Construct a new Join from an association @param association Association between two ActiveRecord::Base objects. @param association_position Association position. Used when the relationship is a many-to-many through. @param origin_table_alias Alias of table that is the origin of the join. @param join [LeftJoin] Join class. @return [LeftJoin] object with the join for this association.

# File lib/babik/queryset/lib/join/join.rb, line 14
def self.new_from_association(association, association_position, origin_table_alias, join = LeftJoin)
  owner_table = association.active_record.table_name
  target_table_alias = "#{owner_table}__#{association.name}_#{association_position}"
  join_keys = association.join_keys

  target_table = TargetTable.new(association.table_name, target_table_alias, join_keys.key)
  origin_table = OriginTable.new(origin_table_alias, join_keys.foreign_key)

  join.new(target_table, origin_table)
end