是否可以使用与自引用的续集关联的任意嵌套深度?

时间:2018-05-23 18:50:34

标签: node.js sequelize.js

我希望在自引用关联上进行递归嵌套,如果可能的话,深度为3或4级。有可能吗?

这有效:

ContentItem.childrenAssoc = ContentItem.belongsToMany(ContentItem, { through: ContentItemChildren, foreignKey: 'ParentId', as: 'Children', }); ContentItem.addScope('detail', { include: [ { model: models.ContentItem, as: 'Children', }, ], });

但是下面的内容失败了: /Users/mkm/clients/frn/sites/frn-platform-meta/backend/node_modules/sequelize/lib/model.js:198 self._expandAttributes(options); TypeError: self._expandAttributes is not a function

ContentItem.childrenAssoc = ContentItem.belongsToMany(ContentItem, { through: ContentItemChildren, foreignKey: 'ParentId', as: 'Children', }); ContentItem.grandChildrenAssoc = ContentItem.belongsToMany(ContentItem, { through: ContentItemChildren, foreignKey: 'ParentId', as: 'GrandChild', }); ContentItem.addScope('detail', { include: [ { model: models.ContentItem, as: 'Children', include: [{model: models.ContentItem.grandChildrenAssoc, as: 'GrandChild'}], }, ], });

欣赏任何建议。谢谢,迈克

0 个答案:

没有答案