Sequelize getter不在model.findall({raw:true})上运行



我的一个Sequelize模型中有一个照片属性。我有一个吸气剂。

photo: {
type: Sequelize.STRING,
get: function () {
if (this.getDataValue("photo"))
return process.env.IMAGE_PREFIX + this.getDataValue("photo")
else
return this.getDataValue("photo")
}
},

但是当我想用({raw:true}(getter查找这个模型中的所有记录时,它不起作用。

const categories = await Category.findAll({
limit: parseInt(limit),
offset: parseInt(offset),
raw: true,
where: {
title: { [Op.like]: '%' + searchString + '%' }
}
});

如果我使用({plain:true}(,只会找到一条记录。

由于sequelize的更新版本,正如文档本身所说:

Getters不会使用instance.get({ raw: true })运行,请使用instance.get({ plain: true })

你可以在这里阅读更多关于

最新更新