In Rails 3, when you do activeRecord.save does the transaction commit or is when the method exits ?
so what I’m trying to figure out is if the MySQL is written right after save! or it’s save after I exit the define black
def something
1000.times do
o = Order.new(:name => "Tomas")
o.save
end
end
You should probably read up a bit on the ActiveRecord object callback chain; it explains what is going on under the hood with your objects.
Basically, when you call save, an ActiveRecord::Base object will go through all the callbacks in the order the documentation lists them, you can see where the commit takes place (in between steps 6 and 7 as of my writing this). ActiveRecord even exposes a callback after the commit happens in case you want some conditional logic when you’re sure something has been committed to the database, but generally we trust that if
savereturns true, everything is fine.So to explicitly answer your question, a commit happens during your save call, not when you exit the method.