diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-08-31 00:14:49 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-08-31 00:14:49 +0100 |
commit | 6d8fc26ce860259d05d4655af584641e4bf33554 (patch) | |
tree | 9a07ca3799c91b0e2bbcebb5daa6bbf32e76e249 /railties | |
parent | 5a310f8335a407f2c95a84f1c73db20846370216 (diff) | |
download | rails-6d8fc26ce860259d05d4655af584641e4bf33554.tar.gz rails-6d8fc26ce860259d05d4655af584641e4bf33554.tar.bz2 rails-6d8fc26ce860259d05d4655af584641e4bf33554.zip |
Fix the readonly section
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 811f45d8b3..70a0ab9fcb 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/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: - -<ruby> -Client.first.readonly(true) -</ruby> - -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. <ruby> -client = Client.first.readonly(true) -client.locked = false +client = Client.readonly.first +client.visits += 1 client.save </ruby> +As +client+ is explicitly set to be a readonly object, the above code will raise an +ActiveRecord::ReadOnlyRecord+ exception when trying to calling +client.save+ 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. |