我希望在自引用关联上进行递归嵌套,如果可能的话,深度为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'}],
},
],
});
欣赏任何建议。谢谢,迈克