加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – mongoid – 在引用1..N关系中从父对象中删除子

发布时间:2020-12-17 02:01:48 所属栏目:百科 来源:网络整理
导读:我注意到的时候: parent.children.delete_all(condition: {obj_id: obj.id}) 然后我做: parent.children 我仍然看到对我试图删除的对象的引用. 如果我改为: parent = Parent.where(id) #get the parent again from dbparent.children 我注意到孩子失踪了.
我注意到的时候:

parent.children.delete_all(condition: {obj_id: obj.id})

然后我做:

parent.children

我仍然看到对我试图删除的对象的引用.

如果我改为:

parent = Parent.where(id) #get the parent again from db
parent.children

我注意到孩子失踪了.

如何确保在删除子项时,将其从db中删除,并在一次操作中从数组中删除引用?

解决方法

尝试使用destroy_all而不是delete_all.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读