postgresql - Rails before_destroy callback db changes always rolled back -
I am trying to remove the model from DB and it is too much to follow (see 9.2.5.3 Exercise < P>
I have a simple model:
class user & lt; ActiveRecord :: base before_destroy update_attribute (: deleted_at, Time.current) incorrect end
>
and in the controller:
Delete def @ user = user # # User.update! (Deleted_at: time.zone.now) #If I do it So it works at user.destroy @ # if I also comment on this line ... render: sh End
Callback is called and the attribute is set, but then the database transaction is always rolled back. I leave it because I false
The model is removed because the deletion execution is not stopped.
As you can see in the comments, I can find it to work, but do I actually have a service object To use So my logic and I want out of the controller.
If your callback incorrectly transmits the transaction will always be rollbacked.
Whatever you want, you should not call the destroy
method on your escale object. Instead, make your own method like soft_destroy
or something else to update your feature.
And to prevent others from calling the destroy
method on their arel objects, just add a callback, for example, raising and exception.
Comments
Post a Comment