Module: JdbcSpec::QuotedPrimaryKeyExtension

Defined in:
lib/active_record/connection_adapters/jdbc_adapter.rb

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 61

def self.extended(base)
  #       Rails 3 method           Rails 2 method
  meth = [:arel_attributes_values, :attributes_with_quotes].detect do |m|
    base.private_instance_methods.include?(m.to_s)
  end
  pk_hash_key = "self.class.primary_key"
  pk_hash_value = '"?"'
  if meth == :arel_attributes_values
    pk_hash_key = "self.class.arel_table[#{pk_hash_key}]"
    pk_hash_value = "Arel::SqlLiteral.new(#{pk_hash_value})"
  end
  if meth
    base.module_eval %{
      alias :#{meth}_pre_pk :#{meth}
      def #{meth}(include_primary_key = true, *args) #:nodoc:
        aq = #{meth}_pre_pk(include_primary_key, *args)
        if connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer)
          aq[#{pk_hash_key}] = #{pk_hash_value} if include_primary_key && aq[#{pk_hash_key}].nil?
        end
        aq
      end
    }
  end
end