當我使用Sequelize創建用戶的新實例時,我從數據庫中獲取完整對象作爲對Create的響應。我試圖阻止Sequelize在創建時返回存儲在我的用戶表中的散列密碼。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.');
};
我可以使用排除財產對我的發現和路線的findAll像下面的例子屬性,但我一直沒能得到它與我的創建工作。
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);
};
的[Sequelize可能重複:不回密碼](https://stackoverflow.com/questions/27972271/sequelize-dont-return-password) – mscheker