File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
test/cases/adapters/postgresql Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -387,20 +387,22 @@ def attributes_with_values(attribute_names)
387
387
attribute_names . index_with { |name | @attributes [ name ] }
388
388
end
389
389
390
- # Filters the primary keys and readonly attributes from the attribute names.
390
+ # Filters the primary keys, readonly attributes and virtual columns from the attribute names.
391
391
def attributes_for_update ( attribute_names )
392
392
attribute_names &= self . class . column_names
393
393
attribute_names . delete_if do |name |
394
- self . class . readonly_attribute? ( name )
394
+ self . class . readonly_attribute? ( name ) ||
395
+ column_for_attribute ( name ) . virtual?
395
396
end
396
397
end
397
398
398
- # Filters out the primary keys, from the attribute names, when the primary
399
+ # Filters out the virtual columns and also primary keys, from the attribute names, when the primary
399
400
# key is to be generated (e.g. the id attribute has no value).
400
401
def attributes_for_create ( attribute_names )
401
402
attribute_names &= self . class . column_names
402
403
attribute_names . delete_if do |name |
403
- pk_attribute? ( name ) && id . nil?
404
+ ( pk_attribute? ( name ) && id . nil? ) ||
405
+ column_for_attribute ( name ) . virtual?
404
406
end
405
407
end
406
408
Original file line number Diff line number Diff line change @@ -87,6 +87,10 @@ def hash
87
87
comment . hash
88
88
end
89
89
90
+ def virtual?
91
+ false
92
+ end
93
+
90
94
private
91
95
def deduplicated
92
96
@name = -name
Original file line number Diff line number Diff line change @@ -23,6 +23,16 @@ def setup
23
23
VirtualColumn . create ( name : "Rails" )
24
24
end
25
25
26
+ def test_virtual_column_with_full_inserts
27
+ partial_inserts_was = VirtualColumn . partial_inserts
28
+ VirtualColumn . partial_inserts = false
29
+ assert_nothing_raised do
30
+ VirtualColumn . create! ( name : "Rails" )
31
+ end
32
+ ensure
33
+ VirtualColumn . partial_inserts = partial_inserts_was
34
+ end
35
+
26
36
def teardown
27
37
@connection . drop_table :virtual_columns , if_exists : true
28
38
VirtualColumn . reset_column_information
You can’t perform that action at this time.
0 commit comments