Reputation: 583
I wanted to override an ActiveRecord save method inorder to bring few things out of the transaction. Is it good idea to override the method?
Upvotes: 3
Views: 1416
Reputation: 44675
In most of the cases the answer is no, as there is a number of callbacks you should use instead: before_save, after_save, before_create and after_create. All those callbacks take the record to be saved (or record which has been saved) as an argument, so you can do whatever you want with those. What's more, if any of those callbacks raises exception or returns false, whole transaction is being rolled back.
However: THIS IS RUBY! Which means you can do whatever you want if you really have to. If callbacks are for some reason not sufficient for you, go ahead and override it. Good example of reason to override it would be adding extra argument (not really recommended as might break other methods) or to handle extra options if those are needed (which is quite neat!)
Upvotes: 8