lib/arel-helpers/join_association.rb
def join_association_5_0(table, association, join_type, options = {})
        aliases = options.fetch(:aliases, [])
        associations = association.is_a?(Array) ? association : [association]
        join_dependency = ActiveRecord::Associations::JoinDependency.new(table, associations, [])

        constraints = join_dependency.join_constraints([], join_type)

        binds = constraints.flat_map do |info|
          prepared_binds = info.binds.map(&:value_for_database)
          prepared_binds.map { |value| table.connection.quote(value) }
        end

        joins = constraints.flat_map do |constraint|
          constraint.joins.map do |join|
            right = if block_given?
              yield join.left.name.to_sym, join.right
            else
              join.right
            end

            if found_alias = find_alias(join.left.name, aliases)
              join.left.table_alias = found_alias.name
            end

            join_type.new(join.left, right)
          end
        end

        join_strings = joins.map do |join|
          to_sql(join, table, binds)
        end

        join_strings.join(' ')
      end
# activerecord uses JoinDependency to automagically generate inner join statements for
# any type of association (belongs_to, has_many, and has_and_belongs_to_many).
# For example, for HABTM associations, two join statements are required.
# This method encapsulates that functionality and yields an intermediate object for chaining.
# It also allows you to use an outer join instead of the default inner via the join_type arg.
activerecord uses JoinDependency to automagically generate inner join statements for
any type of association (belongs_to, has_many, and has_and_belongs_to_many).
For example, for HABTM associations, two join statements are required.
This method encapsulates that functionality and yields an intermediate object for chaining.
It also allows you to use an outer join instead of the default inner via the join_type arg.
activerecord uses JoinDependency to automagically generate inner join statements for any type of association ( belongs_to has_many and has_and_belongs_to_many ) . For example for HABTM associations two join statements are required . This method encapsulates that functionality and yields an intermediate object for chaining . It also allows you to use an outer join instead of the default inner via the join_type arg .
def join_association_5_0(table, association, join_type, options = {})
        aliases = options.fetch(:aliases, [])
        associations = association.is_a?(Array) ? association : [association]
        join_dependency = ActiveRecord::Associations::JoinDependency.new(table, associations, [])
        constraints = join_dependency.join_constraints([], join_type)
        binds = constraints.flat_map do |info|
          prepared_binds = info.binds.map(&:value_for_database)
          prepared_binds.map { |value| table.connection.quote(value) }
        end
        joins = constraints.flat_map do |constraint|
          constraint.joins.map do |join|
            right = if block_given?
              yield join.left.name.to_sym, join.right
            else
              join.right
            end
            if found_alias = find_alias(join.left.name, aliases)
              join.left.table_alias = found_alias.name
            end
            join_type.new(join.left, right)
          end
        end
        join_strings = joins.map do |join|
          to_sql(join, table, binds)
        end
        join_strings.join(' ')
      end
def join_association_5_0 ( table , association , join_type , options = { } ) aliases = options . fetch ( :aliases , [ ] ) associations = association . is_a? ( Array ) ? association : [ association ] join_dependency = ActiveRecord :: Associations :: JoinDependency . new ( table , associations , [ ] ) constraints = join_dependency . join_constraints ( [ ] , join_type ) binds = constraints . flat_map do | info | prepared_binds = info . binds . map ( & :value_for_database ) prepared_binds . map { | value | table . connection . quote ( value ) } end joins = constraints . flat_map do | constraint | constraint . joins . map do | join | right = if block_given? yield join . left . name . to_sym , join . right else join . right end if found_alias = find_alias ( join . left . name , aliases ) join . left . table_alias = found_alias . name end join_type . new ( join . left , right ) end end join_strings = joins . map do | join | to_sql ( join , table , binds ) end join_strings . join ( ' ' ) end
activerecord uses JoinDependency to automagically generate inner join statements for
any type of association (belongs_to, has_many, and has_and_belongs_to_many).
activerecord uses JoinDependency to automagically generate inner join statements for any type of association ( belongs_to has_many and has_and_belongs_to_many ) .
table
association
join_type
options