Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

after_create called after failed saved?

I want to send request to external software whenever I am certain that a model is saved.

1) How do I determine the order in which after_create is called?

2) does it get called on a failed create?

The RAILS API documentation says:

Note that this callback is still wrapped in the transaction around save.

3) Does this mean it requires the save to be successful before after_save is called or does it mean that once save is called after_save is always triggered?

like image 647
Tyler Blatt Avatar asked Sep 01 '15 18:09

Tyler Blatt


Video Answer


1 Answers

How would I learn in what order after_create is called and if it persists through a failed create?

You can read the order of callbacks here: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

If the transaction fails, the save event (and create/update events) return false. This will stop all later callbacks from being run. So, after_save, after_create/after_update all never get run on a failed save (or on a failed create/update).

...and the transaction gets rolled back so the database is not actually updated.

like image 121
Karl Wilbur Avatar answered Oct 12 '22 17:10

Karl Wilbur