Rails 依赖哪些选项是可能的? [英] Rails dependent which options are possible?

查看:45
本文介绍了Rails 依赖哪些选项是可能的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 4 中遇到以下错误

I get the following error in Rails 4

依赖选项必须是destroy delete之一

dependent option must be one of destroy delete

显然https://github.com/rails/rails/issues/3458之前支持其他选项.但是现在有什么可能呢?我找不到任何其他文档

apparently https://github.com/rails/rails/issues/3458 other options were supported before. But what is possible nowadays? I could not find any other documentation

感谢您的帮助

推荐答案

文档可用 这里

似乎支持以下选项:

  • nil - 什么都不做(默认).

  • nil - do nothing (default).

:destroy - 导致所有关联的对象也被销毁.

:destroy - causes all the associated objects to also be destroyed.

:delete_all - 导致直接从数据库中删除所有关联的对象(因此不会执行回调).

:delete_all - causes all the associated objects to be deleted directly from the database (so callbacks will not be executed).

:nullify - 使外键设置为 NULL.不执行回调.

:nullify - causes the foreign keys to be set to NULL. Callbacks are not executed.

:restrict_with_exception - 如果有任何关联记录,则会引发异常.

:restrict_with_exception - causes an exception to be raised if there are any associated records.

:restrict_with_error - 如果有任何关联的对象,则会导致将错误添加到所有者.

:restrict_with_error - causes an error to be added to the owner if there are any associated objects.

这篇关于Rails 依赖哪些选项是可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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