1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge branch 'master' of github.com:brynary/arel

* 'master' of github.com:brynary/arel:
  added missing method visit_Arel_Attributes_Decimal as alias for visit_Arel_Attributes_Attribute
  pass primary key name and value to ActiveRecord adapter insert method
This commit is contained in:
Aaron Patterson 2010-09-28 15:42:47 -07:00
commit 110f8f145c
3 changed files with 16 additions and 3 deletions

View file

@ -163,9 +163,17 @@ module Arel
# FIXME: this method should go away
def insert values
im = InsertManager.new @engine
im.into @ctx.froms
table = @ctx.froms
primary_key_name = (primary_key = table.primary_key) && primary_key.name
# FIXME: in AR tests values sometimes were Array and not Hash therefore is_a?(Hash) check is added
primary_key_value = primary_key && values.is_a?(Hash) && values[primary_key]
im.into table
im.insert values
@engine.connection.insert im.to_sql
# Oracle adapter needs primary key name to generate RETURNING ... INTO ... clause
# for tables which assign primary key value using trigger.
# RETURNING ... INTO ... clause will be added only if primary_key_value is nil
# therefore it is necessary to pass primary key value as well
@engine.connection.insert im.to_sql, 'AREL', primary_key_name, primary_key_value
end
private

View file

@ -27,7 +27,11 @@ module Arel
end
def primary_key
@primary_key ||= self[@engine.connection.primary_key(name)]
@primary_key ||= begin
primary_key_name = @engine.connection.primary_key(name)
# some tables might be without primary key
primary_key_name && self[primary_key_name]
end
end
def alias

View file

@ -234,6 +234,7 @@ module Arel
"#{quote_table_name join_name}.#{quote_column_name o.name}"
end
alias :visit_Arel_Attributes_Integer :visit_Arel_Attributes_Attribute
alias :visit_Arel_Attributes_Decimal :visit_Arel_Attributes_Attribute
alias :visit_Arel_Attributes_String :visit_Arel_Attributes_Attribute
alias :visit_Arel_Attributes_Time :visit_Arel_Attributes_Attribute
alias :visit_Arel_Attributes_Boolean :visit_Arel_Attributes_Attribute