javascript - Sequelize 和 Sequelize 层次结构 : How do I execute an accessor in a model getter?

标签 javascript node.js sequelize.js

我在我的应用中使用 sequelizesequelize-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/

相关文章:

sql - 按位置和顺序对复杂的聚合属性进行 Sequelize

javascript - 从链接设置为悬停状态的 JVectormap

javascript - 在 HTML 中添加滚动条

node.js - async.forEach NodeJS 中的暂停/超时

node.js - 使用NodeJS和Express显示在哪里抛出错误500

mysql - 使用 sequelize 从 child 那里获取父记录

javascript - 如何通过 C++/Javascript 项目跟踪函数和变量的使用

javascript - 使用 html/Javascript 渲染大型钢琴卷

javascript - 如何从内部路由调用模型?

sequelize.js - 内部联接为空时如何更新 res?