diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 2f9970dec1..9fe806425e 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -50,33 +50,28 @@ module ActiveRecord conn = @klass.connection + substitutes = values.to_a + binds = substitutes.map do |arel_attr, value| + [@klass.columns_hash[arel_attr.name], value] + end + + substitutes.each_with_index do |tuple, i| + tuple[1] = conn.substitute_at(tuple.first, i) + end + if values.empty? # empty insert im.values = im.create_values [connection.null_insert_value], [] - @klass.connection.insert( - im.to_sql, - 'SQL', - primary_key, - primary_key_value) else - substitutes = values.to_a - binds = substitutes.map do |arel_attr, value| - [@klass.columns_hash[arel_attr.name], value] - end - substitutes.each_with_index do |tuple, i| - tuple[1] = conn.substitute_at(tuple.first, i) - end - im.insert substitutes - - conn.insert( - im.to_sql, - 'SQL', - primary_key, - primary_key_value, - nil, - binds) end + conn.insert( + im.to_sql, + 'SQL', + primary_key, + primary_key_value, + nil, + binds) end def new(*args, &block) |