评价:依赖=> :破坏

编程入门 行业动态 更新时间:2024-10-22 23:25:23
本文介绍了评价:依赖=> :破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Rails 2.2.2(红宝石1.8.7-P72),我想,以评估之前,实际上这样做破坏物体的影响。即我想是能够产生会受到所有对象的列表:依赖=>:破坏(通过一个对象的关联)。真正的问题,我试图解决的是让用户将被删除的所有内容的列表,并让他们确认操作。

In Rails 2.2.2 (ruby 1.8.7-p72), I'd like to evaluate the impact of destroying an object before actually doing it. I.e. I would like to be able to generate a list of all objects that will be affected by :dependent => :destroy (via an object's associations). The real problem I'm trying to solve is to give a user a list of everything that will be deleted and having them confirm the action.

谁能推荐一个很好的方法来进行此事?我刚刚开始寻找到的ActiveRecord ::协会,但我还没有取得很大进展。

Can anyone recommend a good way to go about this? I've just started looking into ActiveRecord::Associations, but I haven't made much headway.

更新:在我的具体情况,我已经得到了不同程度的对象(A - > B - > C)

Update: In my particular case, I've got various levels of objects (A --> B --> C).

推荐答案

这应该可以帮助您开始......很明显,我们需要自定义,但这种列出了所有协会名称是依赖销毁类BlogEntry:

This should help get you started... Obviously you'll have to customize it but this lists all association names that are dependent destroy on the class BlogEntry:

BlogEntry.reflect_on_all_associations.map do |association| if association.options[:dependent] == :destroy # do something here... association.name end endpact => [:taggings, :comments]

更多推荐

评价:依赖=> :破坏

本文发布于:2023-10-16 05:44:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:评价   GT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!