aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-08-30 23:52:27 +0100
committerPratik Naik <pratiknaik@gmail.com>2010-08-30 23:52:27 +0100
commit0bb32588b7e2badfa708271c0a743444abb76426 (patch)
tree7cb8402cb906a5a1ea9c4cbd9b20494a2f8c3867 /railties/guides/source/active_record_querying.textile
parent9cd708b2cf39219bff3ebcda1e4428403a88a02d (diff)
downloadrails-0bb32588b7e2badfa708271c0a743444abb76426.tar.gz
rails-0bb32588b7e2badfa708271c0a743444abb76426.tar.bz2
rails-0bb32588b7e2badfa708271c0a743444abb76426.zip
Fix pessimistic locking examples
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r--railties/guides/source/active_record_querying.textile8
1 files changed, 4 insertions, 4 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index b34e2ffc03..291989c30e 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -571,13 +571,13 @@ end
h5. Pessimistic Locking
-Pessimistic locking uses a locking mechanism provided by the underlying database. Passing +:lock => true+ to +Model.find+ obtains an exclusive lock on the selected rows. +Model.find+ using +:lock+ are usually wrapped inside a transaction for preventing deadlock conditions.
+Pessimistic locking uses a locking mechanism provided by the underlying database. Using +lock+ when building a relation obtains an exclusive lock on the selected rows. Relations using +lock+ are usually wrapped inside a transaction for preventing deadlock conditions.
For example:
<ruby>
Item.transaction do
- i = Item.first(:lock => true)
+ i = Item.lock.first
i.name = 'Jones'
i.save
end
@@ -592,11 +592,11 @@ Item Update (0.4ms) UPDATE `items` SET `updated_at` = '2009-02-07 18:05:56', `
SQL (0.8ms) COMMIT
</sql>
-You can also pass raw SQL to the +:lock+ option to allow different types of locks. For example, MySQL has an expression called +LOCK IN SHARE MODE+ where you can lock a record but still allow other queries to read it. To specify this expression just pass it in as the lock option:
+You can also pass raw SQL to the +lock+ method for allowing different types of locks. For example, MySQL has an expression called +LOCK IN SHARE MODE+ where you can lock a record but still allow other queries to read it. To specify this expression just pass it in as the lock option:
<ruby>
Item.transaction do
- i = Item.find(1, :lock => "LOCK IN SHARE MODE")
+ i = Item.lock("LOCK IN SHARE MODE").find(1)
i.increment!(:views)
end
</ruby>