gpt4 book ai didi

ruby-on-rails - rails :dependent => :destroy VS :dependent => :delete_all

转载 作者:数据小太阳 更新时间:2023-10-29 06:16:41 25 4
gpt4 key购买 nike

在rails guides中是这样描述的:

Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :dependent => :delete_all

好的,很酷。但是被销毁和被删除有什么区别呢?我都试过了,它似乎做同样的事情。

最佳答案

区别在于回调。

:delete_all 直接在您的应用程序中创建并通过 SQL 删除:

DELETE * FROM users where compagny_id = XXXX

通过 :destroy,您的所有 child 都有一个实例化。所以,如果你不能销毁它或者如果每个都有自己的 :dependent,它的回调可以被调用。

关于ruby-on-rails - rails :dependent => :destroy VS :dependent => :delete_all,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2797339/

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