File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
lib/active_record/attribute_methods Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ def attribute_names_for_partial_inserts
251
251
changed_attribute_names_to_save
252
252
else
253
253
attribute_names . reject do |attr_name |
254
- if column_for_attribute ( attr_name ) . default_function
254
+ if column_for_attribute ( attr_name ) . auto_populated?
255
255
!attribute_changed? ( attr_name )
256
256
end
257
257
end
Original file line number Diff line number Diff line change @@ -972,6 +972,20 @@ def check_around
972
972
end
973
973
end
974
974
975
+ if current_adapter? ( :PostgreSQLAdapter ) && supports_identity_columns?
976
+ test "partial insert off with changed composite identity primary key attribute" do
977
+ klass = Class . new ( ActiveRecord ::Base ) do
978
+ self . table_name = "cpk_postgresql_identity_table"
979
+ end
980
+
981
+ with_partial_writes ( klass , false ) do
982
+ record = klass . create! ( another_id : 10 )
983
+ assert_equal 10 , record . another_id
984
+ assert_not_nil record . id
985
+ end
986
+ end
987
+ end
988
+
975
989
test "attribute_changed? properly type casts enum values" do
976
990
parrot = LiveParrot . create! ( name : "Scipio" , breed : :african )
977
991
Original file line number Diff line number Diff line change 53
53
id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
54
54
)
55
55
SQL
56
+
57
+ drop_table "cpk_postgresql_identity_table" , if_exists : true
58
+ execute <<~SQL
59
+ create table cpk_postgresql_identity_table (
60
+ another_id INT NOT NULL,
61
+ id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
62
+ CONSTRAINT cpk_postgresql_identity_table_pkey PRIMARY KEY (another_id, id)
63
+ )
64
+ SQL
56
65
end
57
66
58
67
create_table :postgresql_times , force : true do |t |
You can’t perform that action at this time.
0 commit comments