File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
activerecord/lib/active_record Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -727,11 +727,29 @@ def strict_loading_all?
727
727
@strict_loading_mode == :all
728
728
end
729
729
730
- # Marks this record as read only.
730
+ # Prevents records from being written to the database:
731
+ #
732
+ # customer = Customer.new
733
+ # customer.readonly!
734
+ # customer.save # raises ActiveRecord::ReadOnlyRecord
735
+ #
736
+ # customer = Customer.first
737
+ # customer.readonly!
738
+ # customer.update(name: 'New Name') # raises ActiveRecord::ReadOnlyRecord
739
+ #
740
+ # Read-only records cannot be deleted from the database either:
731
741
#
732
742
# customer = Customer.first
733
743
# customer.readonly!
734
- # customer.save # Raises an ActiveRecord::ReadOnlyRecord
744
+ # customer.destroy # raises ActiveRecord::ReadOnlyRecord
745
+ #
746
+ # Please, note that the objects themselves are still mutable in memory:
747
+ #
748
+ # customer = Customer.new
749
+ # customer.readonly!
750
+ # customer.name = 'New Name' # OK
751
+ #
752
+ # but you won't be able to persist the changes.
735
753
def readonly!
736
754
@readonly = true
737
755
end
You can’t perform that action at this time.
0 commit comments