-1
我試圖創建使用sequelize用於node.js的所有文檔CRUD一個簡單的更新功能給了我類似的例子,所有導致同樣的錯誤Sequelize文檔更新
Error on update: { dataValues:
{ sku: 'BBB123',
qty_on_hand: 3,
trigger_qty: 4,
replenish_qty: 5,
createdAt: Sun Dec 06 2015 15:31:08 GMT-0500 (EST),
updatedAt: Sun Dec 06 2015 15:31:08 GMT-0500 (EST) },
_previousDataValues:
{ sku: 'BBB123',
qty_on_hand: 3,
trigger_qty: 4,
replenish_qty: 5,
createdAt: Sun Dec 06 2015 15:31:08 GMT-0500 (EST),
updatedAt: Sun Dec 06 2015 15:31:08 GMT-0500 (EST) },
_changed: {},
'$modelOptions':
{ timestamps: true,
instanceMethods: {},
classMethods: {},
validate: {},
freezeTableName: false,
underscored: false,
underscoredAll: false,
paranoid: false,
whereCollection: { sku: 'BBB123' },
schema: null,
schemaDelimiter: '',
defaultScope: null,
scopes: [],
hooks: {},
indexes: [],
name: { plural: 'units', singular: 'unit' },
omitNull: false,
sequelize:
{ options: [Object],
config: [Object],
dialect: [Object],
models: [Object],
modelManager: [Object],
connectionManager: [Object],
importCache: {},
test: [Object],
queryInterface: [Object] },
uniqueKeys: {},
hasPrimaryKeys: true },
'$options':
{ isNewRecord: false,
'$schema': null,
'$schemaDelimiter': '',
raw: true,
attributes:
[ 'sku',
'qty_on_hand',
'trigger_qty',
'replenish_qty',
'createdAt',
'updatedAt' ] },
hasPrimaryKeys: true,
__eagerlyLoadedAssociations: [],
isNewRecord: false }
我的代碼如下所示:
// Update One units
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_update = function(data,success,fail){
// var cleanData = data.sanitize(item);
// if(!cleanData) return false;
unit.find({where:{sku:data.sku}}).then(function (err, data) {
if(err){
console.log("Error on update: ", err);
}
if(data){
data.updateAttributes({
qty_on_hand:20
}).success(function (data) {
console.log("Success on update: ", data);
})
}
});
}
_update({sku:"BBB123"});
有人能告訴我我做錯了什麼嗎?