From 1944cbbbe5a49bc6a0644d30c0464d1850cdca64 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 19 Jan 2012 23:21:28 +0530 Subject: document AR::Base#with_lock in release notes [ci skip] --- railties/guides/source/3_2_release_notes.textile | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/3_2_release_notes.textile b/railties/guides/source/3_2_release_notes.textile index 379b7472c6..7b37681406 100644 --- a/railties/guides/source/3_2_release_notes.textile +++ b/railties/guides/source/3_2_release_notes.textile @@ -373,6 +373,33 @@ has_many :clients, :class_name => :Client # Note that the symbol need to be capi User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson") +* Added a with_lock method to Active Record objects, which starts a transaction, locks the object (pessimistically) and yields to the block. The method takes one (optional) parameter and passes it to +lock!+. + +This makes it possible to write the following: + + +class Order < ActiveRecord::Base + def cancel! + transaction do + lock! + # ... cancelling logic + end + end +end + + +as: + + +class Order < ActiveRecord::Base + def cancel! + with_lock do + # ... cancelling logic + end + end +end + + h4. Deprecations * Automatic closure of connections in threads is deprecated. For example the following code is deprecated: -- cgit v1.2.3