According to the documentation Rails has_many association has clear method. Looks like it executes sql delete query immediately after it performs. Is there a canonical way to delete all the child objects and update association only at the moment of save method? For example:
@cart.container_items.delete_all_example # looks like `clear` execute sql at this line
if @cart.save
# do smth
else
#do smth
end
it is necessary because of many changes at the parent object and they must be committed all or none of them.
Try this:
ActiveRecord::Rollbackis not propagated outside the transaction block. It simply terminates the transaction.