本文介绍了导轨:依赖 =>:摧毁 VS :依赖 =>:删除所有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 rails guides 中是这样描述的:

In rails guides it's described like this:

如果对象与 :dependent =>:destroy,如果它们与 :dependent => 关联,则删除.:delete_all

好吧,酷.但是被销毁和被删除有什么区别呢?我尝试了两者,它似乎做同样的事情.

Right, cool. But what's the difference between being destroyed and being deleted?I tried both and it seems to do the same thing.

推荐答案

区别在于回调.

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

The :delete_all is made directly in your application and deletes by SQL :

DELETE * FROM users where compagny_id = XXXX

使用 :destroy,可以实例化您所有的孩子.所以,如果你不能销毁它或者如果每个都有自己的 :dependent,它的回调可以被调用.

With the :destroy, there is an instantiation of all of your children. So, if you can't destroy it or if each has their own :dependent, its callbacks can be called.

这篇关于导轨:依赖 =>:摧毁 VS :依赖 =>:删除所有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:33