From ab0ce052ba23a4cce7a84ecade0d00d9cc518ebd Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 10 Jan 2009 13:36:09 -0800 Subject: Introduce transaction_joinable flag to mark that the fixtures transaction can't joined, a new savepoint is required even if :requires_new is not set. Use :requires_new option instead of :nest. Update changelog. [#383 state:committed] --- activerecord/lib/active_record/transactions.rb | 27 ++++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'activerecord/lib/active_record/transactions.rb') diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index aaa298dc49..0b6e52c79b 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -137,14 +137,14 @@ module ActiveRecord # # User.find(:all) # => empty # - # It is also possible to treat a certain #transaction call as its own - # sub-transaction, by passing :nest => true to #transaction. If - # anything goes wrong inside that transaction block, then the parent - # transaction will remain unaffected. For example: + # It is also possible to requires a sub-transaction by passing + # :requires_new => true. If anything goes wrong, the + # database rolls back to the beginning of the sub-transaction + # without rolling back the parent transaction. For example: # # User.transaction do # User.create(:username => 'Kotori') - # User.transaction(:nest => true) do + # User.transaction(:requires_new => true) do # User.create(:username => 'Nemu') # raise ActiveRecord::Rollback # end @@ -169,20 +169,17 @@ module ActiveRecord # database error will occur because the savepoint has already been # automatically released. The following example demonstrates the problem: # - # Model.connection.transaction do # BEGIN - # Model.connection.transaction(true) do # CREATE SAVEPOINT rails_savepoint_1 - # Model.connection.create_table(...) # rails_savepoint_1 now automatically released - # end # RELEASE savepoint rails_savepoint_1 - # # ^^^^ BOOM! database error! + # Model.connection.transaction do # BEGIN + # Model.connection.transaction(:requires_new => true) do # CREATE SAVEPOINT active_record_1 + # Model.connection.create_table(...) # active_record_1 now automatically released + # end # RELEASE savepoint active_record_1 + # # ^^^^ BOOM! database error! # end module ClassMethods # See ActiveRecord::Transactions::ClassMethods for detailed documentation. def transaction(options = {}, &block) - options.assert_valid_keys :nest - - # See the API documentation for ConnectionAdapters::DatabaseStatements#transaction - # for useful information. - connection.transaction(options[:nest], &block) + # See the ConnectionAdapters::DatabaseStatements#transaction API docs. + connection.transaction(options, &block) end end -- cgit v1.2.3