【发布时间】:2015-07-09 13:49:19
【问题描述】:
我正在向 sequelize 模型添加一个实例方法。根据the documentation,我应该可以引用this.name,但我能看到的唯一值是this.dataValues.name。我没有理由相信高质量的文档是错误的......但为什么会发生这种情况?
此外,没有可用的 setter 或 getter。 this.getDataValue / this.setDataValue 在 getter / setter 中工作,但不在 instanceMethods 中。
我在网上找不到任何相关示例 - 如果您知道有一个项目可以读取(或更好地写入)这些值,请将其添加到您的回复中。
module.exports = (sequelize: Sequelize, DataTypes: DataTypes) => {
return sequelize.define<UserInstance, UserPojo>('User', {
name: { type: DataTypes.STRING }
}, {
instanceMethods: {
myMethod: (value) => {
// this.name is undefined
// this.dataValues.name IS defined ??
}
}, ...
【问题讨论】:
标签: express sequelize.js