扶手:依赖=> :摧毁VS:依赖=> :删除所有 [英] Rails :dependent => :destroy VS :dependent => :delete_all

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

问题描述

在轨指南,它是这样描述的:

In rails guides it's described like this:

对象将除了破坏,如果他们与相关:依赖=> :摧毁和删除,如果他们正在与相关:依赖=> :DELETE_ALL

Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :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

随着:摧毁,有所有你的孩子的一个实例。所以,如果你不能破坏它,或者如果每个人都有自己的:依赖,它的回调可以被称为

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:依赖=> :删除所有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆