Skip to content

Commit

Permalink
document AR::Base#with_lock in release notes [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaydev committed Jan 19, 2012
1 parent 01d041a commit 1944cbb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions railties/guides/source/3_2_release_notes.textile
Expand Up @@ -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") User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
</ruby> </ruby>


* Added a <tt>with_lock</tt> 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:

<ruby>
class Order < ActiveRecord::Base
def cancel!
transaction do
lock!
# ... cancelling logic
end
end
end
</ruby>

as:

<ruby>
class Order < ActiveRecord::Base
def cancel!
with_lock do
# ... cancelling logic
end
end
end
</ruby>

h4. Deprecations h4. Deprecations


* Automatic closure of connections in threads is deprecated. For example the following code is deprecated: * Automatic closure of connections in threads is deprecated. For example the following code is deprecated:
Expand Down

0 comments on commit 1944cbb

Please sign in to comment.