mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not use primary key on insertion when it's nil
This commit is contained in:
parent
27d0d4fffd
commit
bf22b287a4
1 changed files with 2 additions and 2 deletions
|
@ -258,11 +258,11 @@ module ActiveRecord
|
|||
# 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
|
||||
|
|
Loading…
Reference in a new issue