如何找到ActiveRecord的ROLLBACK的原因 [英] how to find the cause of ActiveRecord ROLLBACK
本文介绍了如何找到ActiveRecord的ROLLBACK的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在日志中我看到一个 ROLLBACK
,但没有记录异常。有没有办法找出是什么原因造成的ROLLBACK?
下面是日志的摘录:
手机负荷(0.4ms)选择电话。*从手机WHERE手机,ID= $ 1 LIMIT 1 [身份证,980190963]
(为0.2ms)BEGIN
用户负载(0.4ms)选择用户。*从用户WHERE的用户。phone_id= 980190963 LIMIT 1
(为0.2ms)ROLLBACK
电话负载(0.4ms)选择电话。*从手机WHERE手机,ID= $ 1 LIMIT 1 [身份证,980190963]
用户负载(0.4ms)选择用户。*从用户WHERE的用户。phone_id= 980190963 LIMIT 1
解决方案
一种方式是手工信息写入日志。尝试像这样从你的控制器:
Rails.logger.info(@ your_object.errors.inspect)
这应该输出所有失败验证的内容。
In the logs I'm seeing a ROLLBACK
, but no exception is logged. Is there a way to find out what caused the ROLLBACK?
Here's the excerpt of the log:
Phone Load (0.4ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = $1 LIMIT 1 [["id", 980190963]]
(0.2ms) BEGIN
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."phone_id" = 980190963 LIMIT 1
(0.2ms) ROLLBACK
Phone Load (0.4ms) SELECT "phones".* FROM "phones" WHERE "phones"."id" = $1 LIMIT 1 [["id", 980190963]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."phone_id" = 980190963 LIMIT 1
解决方案
One way is to manually write information to the log. Try something like this from your controller:
Rails.logger.info(@your_object.errors.inspect)
That should output the content of all validations that failed.
这篇关于如何找到ActiveRecord的ROLLBACK的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文