diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-19 09:38:37 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-19 09:38:37 -0800 |
commit | 0056a7512ae15ca9d43ce8b1dd6600962893be58 (patch) | |
tree | 6e2d8270294fd0016af2e002c75670a1fdd92f82 /railties/guides | |
parent | 01cde0b246d47b2aedcd2568990fb61d384ca173 (diff) | |
parent | 7afbc89c37e56531c9ef4e34369e329aab1b21de (diff) | |
download | rails-0056a7512ae15ca9d43ce8b1dd6600962893be58.tar.gz rails-0056a7512ae15ca9d43ce8b1dd6600962893be58.tar.bz2 rails-0056a7512ae15ca9d43ce8b1dd6600962893be58.zip |
Merge pull request #4531 from exviva/pessimistic_with_lock
Add ActiveRecord::Base#with_lock
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index beada85ce3..5970a45839 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -692,6 +692,17 @@ Item.transaction do end </ruby> +If you already have an instance of your model, you can start a transaction and acquire the lock in one go using the following code: + +<ruby> +item = Item.first +item.with_lock do + # This block is called within a transaction, + # item is already locked. + item.increment!(:views) +end +</ruby> + h3. Joining Tables Active Record provides a finder method called +joins+ for specifying +JOIN+ clauses on the resulting SQL. There are multiple ways to use the +joins+ method. |