Sha256: 4d0822fcd2df7bf5cebfb12f600db978fb8e46f9a3f65b3837f948e399528cb7

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module Arel
  module Visitors
    class ToSql
      def visit_Arel_Attributes_Attribute o, collector
        join_name = o.relation.table_alias || o.relation.name
        table_name = quote_table_name join_name

        if o.name.is_a? Array
          collector <<
            o.name.map{ |field| "#{table_name}.#{quote_column_name(field)}" }.join(",")
        else
          collector << "#{table_name}.#{quote_column_name o.name}"
        end
      end

      def visit_Arel_Nodes_In o, collector
        if Array === o.right && o.right.empty?
          collector << '1=0'
        else
          # CPK
          # collector = visit o.left, collector
          if o.left.respond_to?(:name) && o.left.name.is_a?(Array)
            collector << "("
            collector = visit(o.left, collector)
            collector << ")"
          else
            collector = visit o.left, collector
          end

          collector << " IN ("
          visit(o.right, collector) << ")"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
composite_primary_keys-8.1.8 lib/composite_primary_keys/arel/visitors/to_sql.rb
composite_primary_keys-8.1.7 lib/composite_primary_keys/arel/visitors/to_sql.rb
composite_primary_keys-8.1.6 lib/composite_primary_keys/arel/visitors/to_sql.rb
composite_primary_keys-8.1.5 lib/composite_primary_keys/arel/visitors/to_sql.rb
composite_primary_keys-8.1.4 lib/composite_primary_keys/arel/visitors/to_sql.rb
composite_primary_keys-8.1.3 lib/composite_primary_keys/arel/visitors/to_sql.rb