lib/arel-helpers/join_association.rb
# ActiveRecord 4.2 moves bind variables out of the join classes
# and into the relation. For this reason, a method like
# join_association isn't able to add to the list of bind variables
# dynamically. To get around the problem, this method must return
# a string.
ActiveRecord 4.2 moves bind variables out of the join classes
and into the relation. For this reason, a method like
join_association isn't able to add to the list of bind variables
dynamically. To get around the problem, this method must return
a string.
ActiveRecord 4 . 2 moves bind variables out of the join classes and into the relation . For this reason a method like join_association isn ' t able to add to the list of bind variables dynamically . To get around the problem this method must return a string .
def join_association_4_2(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([])
        binds = constraints.flat_map do |info|
          info.binds.map { |bv| table.connection.quote(*bv.reverse) }
        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_4_2 ( 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 ( [ ] ) binds = constraints . flat_map do | info | info . binds . map { | bv | table . connection . quote ( * bv . reverse ) } 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 4.2 moves bind variables out of the join classes
and into the relation.
ActiveRecord 4 . 2 moves bind variables out of the join classes and into the relation .
table
association
join_type
options