diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index e1cbfecc4f50e..3f829f0029a5a 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -727,11 +727,29 @@ def strict_loading_all? @strict_loading_mode == :all end - # Marks this record as read only. + # Prevents records from being written to the database: + # + # customer = Customer.new + # customer.readonly! + # customer.save # raises ActiveRecord::ReadOnlyRecord + # + # customer = Customer.first + # customer.readonly! + # customer.update(name: 'New Name') # raises ActiveRecord::ReadOnlyRecord + # + # Read-only records cannot be deleted from the database either: # # customer = Customer.first # customer.readonly! - # customer.save # Raises an ActiveRecord::ReadOnlyRecord + # customer.destroy # raises ActiveRecord::ReadOnlyRecord + # + # Please, note that the objects themselves are still mutable in memory: + # + # customer = Customer.new + # customer.readonly! + # customer.name = 'New Name' # OK + # + # but you won't be able to persist the changes. def readonly! @readonly = true end