How do I get ''save'' to execute without commit? I have tried: ActiveRecord::Base.connection.begin_db_transaction # do some stuff that doesn''t issue a database COMMIT statement # then: @myObject.save # this issues a COMMIT but it shouldn''t! Shouldn''t it wait until I''ve called: ActiveRecord::Base.connection.commit_db_transaction ? what am I doing wrong? thanks for any help -- Posted via http://www.ruby-forum.com/.
sorry just found out save and destroy automatically commit. But what about adding linked objects? This will issue a COMMIT: @myObject.items<< @item even though I wrap it in a transaction at the database connection level. -- Posted via http://www.ruby-forum.com/.
Iphan Iphan wrote:> > sorry just found out save and destroy automatically commit. > > But what about adding linked objects? > > This will issue a COMMIT: > > @myObject.items<< @item > > even though I wrap it in a transaction at the database connection level.Have you tried this? MyClass.transaction do my_object.save end -- Josh Susser http://blog.hasmanythrough.com/ -- Posted via http://www.ruby-forum.com/.
> Have you tried this? > > MyClass.transaction do > my_object.save > endI did. The problem is that I need to control from my application when to commit. So I guess I would need to work with the object in memory, push all the CRUD operations into an array, and execute them all within one transaction block. That means all operations are rolled back if one of them fails. Or am I wrong? Basically my users want to have all the INSERT, UPDATE, DELETE statements executed by the database, so they immediately know when one operation failed,eg due to constraints violations, and to control when to issue a COMMIT. Is there a way or workaround to do this in rails ? So far the only statement I found that does an UPDATE without issuing a COMMIT when I set ActiveRecord::Base.connection.begin_db_transaction is update_all and even that only works when I explicitely pass (name, value) pairs for the properties I want to update. -- Posted via http://www.ruby-forum.com/.
look the AR docs for AR:transaction 2006/8/11, Iphan Iphan <iphan@isb-sib.ch>:> > > > Have you tried this? > > > > MyClass.transaction do > > my_object.save > > end > > I did. The problem is that I need to control from my application when to > commit. So I guess I would need to work with the object in memory, push > all the CRUD operations into an array, and execute them all within one > transaction block. That means all operations are rolled back if one of > them fails. Or am I wrong? > > Basically my users want to have all the INSERT, UPDATE, DELETE > statements executed by the database, so they immediately know when one > operation failed,eg due to constraints violations, and to control when > to issue a COMMIT. > > Is there a way or workaround to do this in rails ? So far the only > statement I found that does an UPDATE without issuing a COMMIT when I > set > > ActiveRecord::Base.connection.begin_db_transaction > > is update_all and even that only works when I explicitely pass (name, > value) pairs for the properties I want to update. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060811/0f34e1a4/attachment-0001.html
Michael Siebert wrote:> look the AR docs for AR:transactionit is because that doc did not help that I posted in this forum. AR::transaction examples will issue all SQL commands within the transaction block in one go. How do I create rails actions (insert, delete, update) with a separate ''commit'' action? I mean I cannot have an open ''transaction do'' line, or am I wrong? Can I use some sort of ''yield'' command to wrap my rails actions in a transaction block? -- Posted via http://www.ruby-forum.com/.
On 8/16/06, Iphan Iphan <iphan@isb-sib.ch> wrote:> Michael Siebert wrote: > > look the AR docs for AR:transaction > > it is because that doc did not help that I posted in this forum. > > AR::transaction examples will issue all SQL commands within the > transaction block in one go. > > How do I create rails actions (insert, delete, update) with a separate > ''commit'' action? I mean I cannot have an open ''transaction do'' line, or > am I wrong? Can I use some sort of ''yield'' command to wrap my rails > actions in a transaction block?If i understand correctly, you want transactions that span multiple requests? I''m pretty sure rails won''t do that, and even on platforms that "support it", I have the impression it''s a fairly daft idea. Keep the data somewhere else until ready to commit, e.g. in the session if there''s not too much data or you don''t need it to scale. Isak