Permalink
Browse files

Do not use primary key on insertion when it's nil

  • Loading branch information...
1 parent 27d0d4f commit bf22b287a4720cd4e5fc4206262a09ebf490609a @spastorino spastorino committed Dec 29, 2010
Showing with 2 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/persistence.rb
@@ -258,11 +258,11 @@ def update(attribute_names = @attributes.keys)
# Creates a record with values matching those of the instance attributes
# and returns its id.
def create
- if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name)
+ if id.nil? && connection.prefetch_primary_key?(self.class.table_name)
self.id = connection.next_sequence_value(self.class.sequence_name)
end
- attributes_values = arel_attributes_values
+ attributes_values = arel_attributes_values(!id.nil?)
new_id = if attributes_values.empty?
self.class.unscoped.insert connection.empty_insert_statement_value

0 comments on commit bf22b28

Please sign in to comment.