Skip to content

Commit

Permalink
Deprecation: object transactions warning.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5405 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 2, 2006
1 parent 7ca2b65 commit 88d9b32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Deprecation: object transactions warning. [Jeremy Kemper]

* has_one :dependent => :nullify ignores nil associates. #6528 [janovetz, Jeremy Kemper]

* Oracle: resolve test failures, use prefetched primary key for inserts, check for null defaults. Factor out some common methods from all adapters. #6515 [Michael Schoen]
Expand Down
19 changes: 14 additions & 5 deletions activerecord/lib/active_record/transactions.rb
Expand Up @@ -55,7 +55,7 @@ def self.included(base)
# will happen under the protected cover of a transaction. So you can use validations to check for values that the transaction
# depend on or you can raise exceptions in the callbacks to rollback.
#
# == Object-level transactions
# == Object-level transactions (deprecated)
#
# You can enable object-level transactions for Active Record objects, though. You do this by naming each of the Active Records
# that you want to enable object-level transactions for, like this:
Expand All @@ -65,8 +65,14 @@ def self.included(base)
# mary.deposit(100)
# end
#
# If the transaction fails, David and Mary will be returned to their pre-transactional state. No money will have changed hands in
# neither object nor database.
# If the transaction fails, David and Mary will be returned to their
# pre-transactional state. No money will have changed hands in neither
# object nor database.
#
# However, useful state such as validation errors are also rolled back,
# limiting the usefulness of this feature. As such it is deprecated in
# Rails 1.2 and will be removed in the next release. Install the
# object_transactions plugin if you wish to continue using it.
#
# == Exception handling
#
Expand All @@ -80,8 +86,11 @@ def transaction(*objects, &block)
increment_open_transactions

begin
objects.each { |o| o.extend(Transaction::Simple) }
objects.each { |o| o.start_transaction }
unless objects.empty?
ActiveSupport::Deprecation.warn "Object transactions are deprecated and will be removed from Rails 2.0. See http://www.rubyonrails.org/deprecation for details.", caller
objects.each { |o| o.extend(Transaction::Simple) }
objects.each { |o| o.start_transaction }
end

result = connection.transaction(Thread.current['start_db_transaction'], &block)

Expand Down
14 changes: 8 additions & 6 deletions activerecord/test/transactions_test.rb
Expand Up @@ -90,12 +90,14 @@ def test_failing_with_object_rollback
assert !@first.approved?, "First should be unapproved initially"

begin
Topic.transaction(@first, @second) do
@first.approved = true
@second.approved = false
@first.save
@second.save
raise "Bad things!"
assert_deprecated /Object transactions/ do
Topic.transaction(@first, @second) do
@first.approved = true
@second.approved = false
@first.save
@second.save
raise "Bad things!"
end
end
rescue
# caught it
Expand Down

0 comments on commit 88d9b32

Please sign in to comment.