【发布时间】:2021-03-25 11:27:51
【问题描述】:
当我使用 Sequelize 创建我的用户的新实例时,我会从数据库返回完整对象作为对 Create 的响应。我试图阻止 Sequelize 在创建时返回存储在我的用户表中的散列密码。
exports.create = (payload, err, success) => {
db.user.create(payload).then(success).catch(err);
console.log('Created new user record.');
};
我尝试使用 exclude 属性,但返回完整对象。
exports.create = (payload, err, success) => {
db.user.create(payload, {
attributes: {
exclude: ['password']
}
}).then(success).catch(err);
console.log('Created new user record.');
};
我可以在我的 find 和 findAll 路由的属性中使用 exclude 属性,如下例所示,但我无法让它与我的 create 一起使用。
exports.find = (payload, err, success) => {
db.user.find({
where: {
id: payload.id,
},
attributes: {
exclude: ['password']
}
}).then(success).catch(err);
console.log('Retrieved user record with id: ' + payload.id);
};
【问题讨论】:
标签: node.js sequelize.js