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:39:20 -0800 |
commit | 4c5b73fef8a41bd2bd8435fa4b00f7c40b721650 (patch) | |
tree | e365d2a2478ef3c81baecea85c9aff638509f4ca /railties/guides/source | |
parent | 00554568e0625b2e4d4212ab7464f02234f74427 (diff) | |
download | rails-4c5b73fef8a41bd2bd8435fa4b00f7c40b721650.tar.gz rails-4c5b73fef8a41bd2bd8435fa4b00f7c40b721650.tar.bz2 rails-4c5b73fef8a41bd2bd8435fa4b00f7c40b721650.zip |
Merge pull request #4531 from exviva/pessimistic_with_lock
Add ActiveRecord::Base#with_lock
Diffstat (limited to 'railties/guides/source')
-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. |