mirror of https://github.com/rails/rails
Fix non-partial inserts for models with composite identity primary keys
This commit is contained in:
parent
965b8c372a
commit
0318c34cb3
|
@ -251,7 +251,7 @@ module ActiveRecord
|
|||
changed_attribute_names_to_save
|
||||
else
|
||||
attribute_names.reject do |attr_name|
|
||||
if column_for_attribute(attr_name).default_function
|
||||
if column_for_attribute(attr_name).auto_populated?
|
||||
!attribute_changed?(attr_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -972,6 +972,20 @@ class DirtyTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
if current_adapter?(:PostgreSQLAdapter) && supports_identity_columns?
|
||||
test "partial insert off with changed composite identity primary key attribute" do
|
||||
klass = Class.new(ActiveRecord::Base) do
|
||||
self.table_name = "cpk_postgresql_identity_table"
|
||||
end
|
||||
|
||||
with_partial_writes(klass, false) do
|
||||
record = klass.create!(another_id: 10)
|
||||
assert_equal 10, record.another_id
|
||||
assert_not_nil record.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "attribute_changed? properly type casts enum values" do
|
||||
parrot = LiveParrot.create!(name: "Scipio", breed: :african)
|
||||
|
||||
|
|
|
@ -53,6 +53,15 @@ ActiveRecord::Schema.define do
|
|||
id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
|
||||
)
|
||||
SQL
|
||||
|
||||
drop_table "cpk_postgresql_identity_table", if_exists: true
|
||||
execute <<~SQL
|
||||
create table cpk_postgresql_identity_table (
|
||||
another_id INT NOT NULL,
|
||||
id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
CONSTRAINT cpk_postgresql_identity_table_pkey PRIMARY KEY (another_id, id)
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
create_table :postgresql_times, force: true do |t|
|
||||
|
|
Loading…
Reference in New Issue