Object Level Transactions

In the README file of the ActiveRecord docs
(http://api.rubyonrails.com/files/vendor/rails/activerecord/README.html)
it says:

Transaction support on both a database and object level. The latter is
implemented by using Transaction::Simple

Just database transaction

Account.transaction do
david.withdrawal(100)
mary.deposit(100)
end

Database and object transaction

Account.transaction(david, mary) do
david.withdrawal(100)
mary.deposit(100)
end

But the second case does not seem to actually be implemented. Test
case:

from script/console I run

irb> a = Account.create
=> #<Account id: 2, name: nil, balance: 0.0>
irb> Account.transaction do
irb* a.deposit(10.00)
irb> raise
irb> end
RuntimeError:
[[snip]]
irb> a.balance #Oops db didn’t change but object did
=> 10.0
irb> a.reload
=> #<Account id: 2, name: nil, balance: 0.0>
irb> Account.transaction(a) do #this should fix it
irb* a.deposit(10.00)
irb> raise
irb> end
ArgumentError: wrong number of arguments (1 for 0)
from (irb):23:in `transaction’
from (irb):23

What am I doing wrong here?

On 05 Feb 2008, at 00:17, Starr T. wrote:

david.withdrawal(100)
mary.deposit(100)

end

Database and object transaction

Account.transaction(david, mary) do
david.withdrawal(100)
mary.deposit(100)
end

Object level transactions have been deprecated in Rails 2, but you
can use a plugin to restore its functionality:
http://ryandaigle.com/articles/2007/3/20/what-s-new-in-edge-rails-
object-transactions-are-out

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 05 Feb 2008, at 00:17, Starr T. wrote:

Object level transactions have been deprecated in Rails 2, but you
can use a plugin to restore its functionality:
http://ryandaigle.com/articles/2007/3/20/what-s-new-in-edge-rails-
object-transactions-are-out

Best regards

Peter De Berdt

Shouldn’t this reference be removed from the documentation then?

Peter De Berdt wrote:

On 05 Feb 2008, at 22:13, Starr T. wrote:

Object level transactions have been deprecated in Rails 2, but you
can use a plugin to restore its functionality:
http://ryandaigle.com/articles/2007/3/20/what-s-new-in-edge-rails-
object-transactions-are-out

Shouldn’t this reference be removed from the documentation then?

You should only rely on well generated api docs on your local
computer and the official docs at api.rubyonrails.com (local docs
install is still best, especially if you’re on edge)

Best regards

Peter De Berdt

Please take a look at the official docs here:
(Peak Obsession)

What I quoted if from the 8th bullet point down.

I do us my locally generated RDocs but I cannot link to them very well
can I?

On 06 Feb 2008, at 00:03, Starr T. wrote:

install is still best, especially if you’re on edge)

Please take a look at the official docs here:
(Peak Obsession
README.html)

What I quoted if from the 8th bullet point down.

I do us my locally generated RDocs but I cannot link to them very well
can I?

:slight_smile:

It must have slipped under the radar, I guess (it happens when it’s
on a summary page). It would be nice if you could submit a patch for
it so it doesn’t persist in later versions.

Best regards

Peter De Berdt

On 05 Feb 2008, at 22:13, Starr T. wrote:

Object level transactions have been deprecated in Rails 2, but you
can use a plugin to restore its functionality:
http://ryandaigle.com/articles/2007/3/20/what-s-new-in-edge-rails-
object-transactions-are-out

Shouldn’t this reference be removed from the documentation then?

I don’t know what site you are using, but I can’t find it in the
official rails api docs at:
http://api.rubyonrails.com/classes/ActiveRecord/Transactions/
ClassMethods.html

It does come up at
http://www.railsapi.org/ActiveRecord::Transactions::ClassMethods
which means that unofficial rails api hasn’t been updated to the
latest version.

You should only rely on well generated api docs on your local
computer and the official docs at api.rubyonrails.com (local docs
install is still best, especially if you’re on edge)

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 06 Feb 2008, at 00:03, Starr T. wrote:

install is still best, especially if you’re on edge)

Please take a look at the official docs here:
(Peak Obsession
README.html)

What I quoted if from the 8th bullet point down.

I do us my locally generated RDocs but I cannot link to them very well
can I?

:slight_smile:

It must have slipped under the radar, I guess (it happens when it’s
on a summary page). It would be nice if you could submit a patch for
it so it doesn’t persist in later versions.

Best regards

Peter De Berdt

Patch #11052 submitted. Thanks for all you help

http://dev.rubyonrails.org/ticket/11052