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

        join_dependency.join_associations.each do |assoc|
          assoc.join_type = join_type
          assoc.join_to(manager)
        end

        manager.join_sources.map do |assoc|
          if found_alias = find_alias(assoc.left.name, aliases)
            assoc.left.table_alias = found_alias.name
          end

          if block_given?
            # yield |assoc_name, join_conditions|
            right = yield assoc.left.name.to_sym, assoc.right
            assoc.class.new(assoc.left, right)
          else
            assoc
          end
        end
      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_3_1(table, association, join_type, options = {})
        aliases = options.fetch(:aliases, {})
        associations = association.is_a?(Array) ? association : [association]
        join_dependency = ActiveRecord::Associations::JoinDependency.new(table, associations, [])
        manager = Arel::SelectManager.new(table)
        join_dependency.join_associations.each do |assoc|
          assoc.join_type = join_type
          assoc.join_to(manager)
        end
        manager.join_sources.map do |assoc|
          if found_alias = find_alias(assoc.left.name, aliases)
            assoc.left.table_alias = found_alias.name
          end
          if block_given?
            right = yield assoc.left.name.to_sym, assoc.right
            assoc.class.new(assoc.left, right)
          else
            assoc
          end
        end
      end
def join_association_3_1 ( table , association , join_type , options = { } ) aliases = options . fetch ( :aliases , { } ) associations = association . is_a? ( Array ) ? association : [ association ] join_dependency = ActiveRecord :: Associations :: JoinDependency . new ( table , associations , [ ] ) manager = Arel :: SelectManager . new ( table ) join_dependency . join_associations . each do | assoc | assoc . join_type = join_type assoc . join_to ( manager ) end manager . join_sources . map do | assoc | if found_alias = find_alias ( assoc . left . name , aliases ) assoc . left . table_alias = found_alias . name end if block_given? right = yield assoc . left . name . to_sym , assoc . right assoc . class . new ( assoc . left , right ) else assoc end end 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 ) .
# yield |assoc_name, join_conditions|
table
association
join_type
options