When do you do activeRecord.save makes a transaction or when does the method exit?

In Rails 3, when do you do activeRecord.save the transaction is committed or when does the method exit?

so I'm trying to figure out if MySQL is written right after saving! or it persists after I exit the definition of black

def something 1000.times do o = Order.new(:name => "Tomas") o.save end end 
+4
source share
1 answer

You should probably read some information about the ActiveRecord object callback chain ; he explains what happens under the hood with your objects.

Basically, when you call save, the ActiveRecord :: Base object will go through all the callbacks in the order specified in the documentation, you can see where the commit happens (in between steps 6 and 7 at the time of writing this). ActiveRecord even provides a callback after committing in case you want to get some conditional logic when you are sure that something has been transferred to the database, but, as a rule, we trust that if save returns true, everything is fine .

In order to explicitly answer your question, the commit occurs during the save call, and not when the method exits.

+4
source

All Articles