我发现在rails destroy方法中,一个额外的事务将包装在查询上。因此,当我尝试以下时,它不起作用。
ActiveRecord::Base.transaction do
@model_a.destroy_all
@new_model_list.each do |item|
item.create!
# Error occurs some point
# No rollback for those deleted records
end
end
答案 0 :(得分:0)
尝试将其重写为:
ActiveRecord::Base.connection.transaction do
@model_a.destroy_all
@new_model_list.each do |item|
item.create!
# Error occurs some point
# No rollback for those deleted records
end
end