级联错误,具有强制性的一对多关系

时间:2018-12-09 00:37:14

标签: sails.js

我正在使用Sails 1.1.0。我用sails-disksails-mongo适配器尝试了以下方法。

我创建了一个强制性的一对多关系。 Sofa具有ownerUser一对多,而Sofa也具有home到{{1}一对多1}}。但是,当我Home await Home.destroy(homeId);时,它没有级联并删除Home。相反,我得到了错误:

Sofa

这是我的模型关联:

PropagationError: Failed to run the "cascade" polyfill.  Could not propagate the potential destruction of this home record.
Details:
  Cannot wipe the contents of association (`sofas`) because there is one conflicting shame record whose `home` cannot be set to `null`.  (That attribute is required.)

This error originated from the fact that the "cascade" polyfill was enabled for this query.
Tip: Try reordering your .destroy() calls.
 [?] See https://sailsjs.com/support for more help.

有人知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

我最近遇到了同样的问题,使用带 inMemoryOnly: true 选项的sails-disk 适配器,您不需要清理数据库,因为只有内存,测试完成后会自动清理。

datastores: {
  default: {
    adapter: 'sails-disk',
    inMemoryOnly: true
  },
}