有一天,我注意到我的交易不接受ActiveRecord :: Rollback。我有这样一个例子:



ActiveRecord::Base.transaction do
    puts @shipment_list.status
    @shipment_list.update(shipment_list_params)
    raise ActiveRecord::Rollback
end
puts @shipment_list.status


结果

CACHE (0.0ms)  SELECT  `shipment_lists`.* FROM `shipment_lists`  WHERE `shipment_lists`.`id` = 24121  ORDER BY created_at DESC LIMIT 1  [["id", "24121"]]
(0.2ms)  BEGIN
reserve
(1.3ms)  SELECT MAX(`audits`.`version`) AS max_id FROM `audits`  WHERE `audits`.`auditable_id` = 24121 AND `audits`.`auditable_type` = 'ShipmentList'
SQL (160.5ms)  INSERT INTO `audits` (`action`, `auditable_id`, `auditable_type`, `audited_changes`, `created_at`, `remote_address`, `request_uuid`, `user_id`, `user_type`, `version`) VALUES ('update', 24121, 'ShipmentList', '---\nstatus:\n- reserve\n- 2\n', '2016-07-10 12:01:55', '127.0.0.1', 'efc5b6e7-c3f9-4b4a-a0fd-67651b2eeb20', 18, 'User', 19)
SQL (0.3ms)  UPDATE `shipment_lists` SET `status` = 2, `updated_at` = '2016-07-10 12:01:55' WHERE `shipment_lists`.`id` = 24121
(0.2ms)  ROLLBACK
bill


错误在哪里?我真的很麻烦。

最佳答案

实际上,问题是由myISAM mysql模式引起的。不允许事务回滚。

关于mysql - ActiveRecord::Rollback似乎不执行事务回滚,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38291749/

10-11 08:21