File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
activerecord/lib/active_record Expand file tree Collapse file tree 1 file changed +6
-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
You can’t perform that action at this time.
0 commit comments