我在我的应用中使用 sequelize
和 sequelize-hierarchy
,并部分定义了如下模型:
ancestors : {
type: orm.Sequelize.VIRTUAL,
get: function() { return 'TODO how return getAncestors here?' }
}
在 getter 内部,如何访问 sequelize-hierarchy
提供的 getAncestors()
方法?
最佳答案
@leroydev 感谢您的记录;)
正如开发人员在该问题中对我所说:
I'm afraid this isn't possible. You'd need to load the ancestors first with include. A getter can't execute asynchronously, and therefore can't fetch the ancestors from the database. When you use include, it fetches them at the same time as the main query.
This is a limitation of Sequelize (actually I think quite a reasonable one). I'm afraid there's nothing I can do about it, so am closing this PR.
引用:https://github.com/overlookmotel/sequelize-hierarchy/issues/20
关于javascript - Sequelize 和 Sequelize 层次结构 : How do I execute an accessor in a model getter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32259251/