Save without commit?

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

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.

Iphan I. 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 S.
http://blog.hasmanythrough.com/

look the AR docs for AR:transaction

2006/8/11, Iphan I. [email protected]:

all the CRUD operations into an array, and execute them all within one
set
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Michael S. [email protected]

www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium

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.

Michael S. 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?

On 8/16/06, Iphan I. [email protected] wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs