代码之家  ›  专栏  ›  技术社区  ›  Noitidart

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

  •  2
  • Noitidart  · 技术社区  · 7 年前

    我用的是帆1.1.0。我试过下面的 sails-disk 和 sails-mongo 适配器。

    我创建了一个强制的一对多关系。一个 Sofa 有 owner 一对多 User 以及 沙发 也有一个 home 是一对多 Home . 但是当我 await Home.destroy(homeId); 这个 家 ,它不会级联并删除 沙发 . 相反,我得到错误:

    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.
    

    以下是我的模特协会:

    // api\models\Sofa.js
    
        owner: {
          model: 'user',
          required: true
        },
    
        home: {
          model: 'home',
          required: true
        },
    
    // api\models\User.js    
    
            sofas: {
               collection: 'sofa',
               via: 'owner'
            },
    
    // api\models\Home.js    
    
            sofas: {
               collection: 'sofa',
               via: 'home'
            },
    

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

    0 回复  |  直到 7 年前
    推荐文章