mirror of https://github.com/rails/rails
Merge pull request #16456 from lsylvester/improve-active-record-error-message-on-update_columns-for-destroyed-records
Change error message in update_columns for destroyed objects
This commit is contained in:
commit
b45b99894a
|
@ -1,3 +1,9 @@
|
|||
* When calling `update_columns` on a record that is not persisted, the error
|
||||
message now reflects whether that object is a new record or has been
|
||||
destroyed.
|
||||
|
||||
*Lachlan Sylvester*
|
||||
|
||||
* Define `id_was` to get the previous value of the primary key.
|
||||
|
||||
Currently when we call id_was and we have a custom primary key name
|
||||
|
|
|
@ -287,7 +287,8 @@ module ActiveRecord
|
|||
# This method raises an +ActiveRecord::ActiveRecordError+ when called on new
|
||||
# objects, or when at least one of the attributes is marked as readonly.
|
||||
def update_columns(attributes)
|
||||
raise ActiveRecordError, "cannot update on a new record object" unless persisted?
|
||||
raise ActiveRecordError, "cannot update a new record" if new_record?
|
||||
raise ActiveRecordError, "cannot update a destroyed record" if destroyed?
|
||||
|
||||
attributes.each_key do |key|
|
||||
verify_readonly_attribute(key.to_s)
|
||||
|
|
Loading…
Reference in New Issue