gpt4 book ai didi

ruby-on-rails - after_create保存失败后调用?

转载 作者:行者123 更新时间:2023-12-04 04:16:40 25 4
gpt4 key购买 nike

每当我确定已保存模型时,我都希望向外部软件发送请求。

1)如何确定调用after_create的顺序?

2)是否在失败的创建中调用它?

RAILS API文档说:

Note that this callback is still wrapped in the transaction around save.



3)这是否意味着在调用 save之前要求 after_save成功,还是意味着一旦触发 save总是会触发 after_save

最佳答案

How would I learn in what order after_create is called and if it persists through a failed create?



您可以在此处阅读回调的顺序:
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

如果事务失败,则 save事件(和 create/ update事件)返回 false。这将停止运行所有以后的回调。因此, after_saveafter_create/ after_update都永远不会在失败的 save(或失败的 create/ update)上运行。

...并且交易被回滚,因此实际上并未更新数据库。

关于ruby-on-rails - after_create保存失败后调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com