新手问题 数据被依赖的话不能删除这个要怎么写

dxwts · January 16, 2014 · Last by dxwts replied at January 22, 2014 · 2248 hits

mongoid 中 has_many 的关系,如果 child 有 parent 那么 child 就不能直接删除,这个要怎么写? 我想到的是在 child 中使用 before_destroy 检查 child.parent?,然后再进行删除,有没有类似在 parent 中使用的:dependent => :destroy 约束选项

请自行 google

关键字 rails has_many dependent restrict

查 Mongoid 官网 Document http://mongoid.org/en/mongoid/docs/relations.html 不过child有parent那么child就不能直接删除这个规则是不是反了?

#2 楼 @lewis 谢谢,没反,需求就是这样,如果 child 有 parent 不能把这个 child 删除

You need to Sign in before reply, if you don't have an account, please Sign up first.