Browse files

Fix the readonly section

  • Loading branch information...
lifo committed Aug 30, 2010
1 parent 5a310f8 commit 6d8fc26ce860259d05d4655af584641e4bf33554
Showing with 5 additions and 11 deletions.
  1. +5 −11 railties/guides/source/active_record_querying.textile
@@ -509,22 +509,16 @@ This will return single order objects for each day, but only for the last month.
h4. Readonly Objects
-To explicitly disallow modification/destruction of the matching records returned in a Relation object, you could chain the +readonly+ method as +true+ to the find call.
-Any attempt to alter or destroy the readonly records will not succeed, raising an +ActiveRecord::ReadOnlyRecord+ exception. To set this option, specify it like this:
-For example, calling the following code will raise an +ActiveRecord::ReadOnlyRecord+ exception:
+Active Record provides +readonly+ method on a relation to explicitly disallow modification or deletion of any of the returned object. Any attempt to alter or destroy a readonly record will not succeed, raising an +ActiveRecord::ReadOnlyRecord+ exception.
-client = Client.first.readonly(true)
-client.locked = false
+client = Client.readonly.first
+client.visits += 1
+As +client+ is explicitly set to be a readonly object, the above code will raise an +ActiveRecord::ReadOnlyRecord+ exception when trying to calling with an updated value of _visists_.
h4. Locking Records for Update
Locking is helpful for preventing race conditions when updating records in the database and ensuring atomic updates.

0 comments on commit 6d8fc26

Please sign in to comment.