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

dxwts · 2014年01月16日 · 最后由 dxwts 回复于 2014年01月22日 · 2248 次阅读

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 删除

需要 登录 后方可回复, 如果你还没有账号请 注册新账号