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

Merge pull request #25620 from kamipo/create_without_primary_key

Pass `pk: false` to `connection.insert` explicitly if do not have a primary key
This commit is contained in:
Rafael França 2016-07-01 21:12:49 -03:00 committed by GitHub
commit 71acc3bd01
2 changed files with 9 additions and 1 deletions

View file

@ -65,7 +65,7 @@ module ActiveRecord
@klass.connection.insert(
im,
'SQL',
primary_key,
primary_key || false,
primary_key_value,
nil,
binds)

View file

@ -174,6 +174,14 @@ class PrimaryKeysTest < ActiveRecord::TestCase
assert_equal '2', dashboard.id
end
def test_create_without_primary_key_no_extra_query
klass = Class.new(ActiveRecord::Base) do
self.table_name = 'dashboards'
end
klass.create! # warmup schema cache
assert_queries(3, ignore_none: true) { klass.create! }
end
if current_adapter?(:PostgreSQLAdapter)
def test_serial_with_quoted_sequence_name
column = MixedCaseMonkey.columns_hash[MixedCaseMonkey.primary_key]