sequelize 和 sequelize-hierarchy:如何在模型 getter 中执行访问器?
sequelize and sequelize-hierarchy: How do I execute an accessor in a model getter?
我在我的应用中使用 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
我在我的应用中使用 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