在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]更多推荐
评价:依赖=> :破坏
发布评论