Are you using MySQL? If so, the default setup will give you some woes if
you try to do something like:
transaction do
task = Task.new(...)
tasks = Task.all
task.save
Task.all # This will return the same as `tasks`, and won't include
your new task
end
There is a way to change that behaviour, I believe...
Ben Hoskings wrote:
On 1 February 2011 16:36, Chris Mayan <[email protected]
<mailto:[email protected]>> wrote:
Hi all,
Just quick query that's been bugging me this afternoon:
Is .save / .save! synchronous?
i.e. After I call that line - should the database row be created in
the DB before executing the next line?
I'm just puzzled as to why step by step debugging, I don't see the DB
row created at all even several lines afterwards.
Is this because the .save! is inside a transaction block, so Rails on
purpose does not actually do any DB actions until the very end of the
transaction block?
It's definitely a synchronous call, in that the database has received
the INSERT/UPDATE command before #save[!] returns.
But, if you're in a transaction you won't be able to see the data in
any other context until the database receives COMMIT when the
transaction block closes.
—Ben
--
You received this message because you are subscribed to the Google
Groups "Ruby or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ruby or
Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.