# Object Level Transactions

**URL:** <https://www.ruby-forum.com/t/object-level-transactions/128093>\
**Category:** Rails\
**Created:** [February 5, 2008, 12:17am UTC](https://www.ruby-forum.com/t/object-level-transactions/128093 "2008-02-05T00:17:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 5, 2008, 12:17am UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/1 "2008-02-05T00:17:50Z")

</div>

In the README file of the ActiveRecord docs  
([http://api.rubyonrails.com/files/vendor/rails/activerecord/README.html](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?

---

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 5, 2008, 12:46am UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/2 "2008-02-05T00:46:08Z")

</div>

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-](http://ryandaigle.com/articles/2007/3/20/what-s-new-in-edge-rails-)  
object-transactions-are-out

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 5, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/3 "2008-02-05T22:13:36Z")

</div>

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-](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?

---

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 6, 2008, 12:03am UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/4 "2008-02-06T00:03:00Z")

</div>

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-](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](http://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](http://api.rubyonrails.com/files/vendor/rails/activerecord/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?

---

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 6, 2008, 9:40am UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/5 "2008-02-06T09:40:25Z")

</div>

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](http://api.rubyonrails.com/files/vendor/rails/activerecord/)  
> 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?

🙂

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

---

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 5, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/6 "2008-02-05T23:48:34Z")

</div>

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-](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/](http://api.rubyonrails.com/classes/ActiveRecord/Transactions/)  
ClassMethods.html

It does come up at  
[http://www.railsapi.org/ActiveRecord::Transactions::ClassMethods](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](http://api.rubyonrails.com) (local docs  
install is still best, especially if you’re on edge)

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![startrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@startrader](https://www.ruby-forum.com/u/startrader)\
**Post date:** [February 8, 2008, 1:36am UTC](https://www.ruby-forum.com/t/object-level-transactions/128093/7 "2008-02-08T01:36:53Z")

</div>

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](http://api.rubyonrails.com/files/vendor/rails/activerecord/)  
> > 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?
> 
> 🙂
> 
> 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](http://dev.rubyonrails.org/ticket/11052)
