Sequelize踩的坑

save篇

contract_id设置了主键,save不支持赋值更改

1
2
3
4
5
6
7
8
let contractGood = yield models.ContractGood.findOne({
where: {
GUID: 1333170
},
transaction: t
});
contractGood.contract_id = '111111111111111111111111';
yield contractGood.save({ transaction: t });

正确使用方式update或delete contractGood.contract_id 再赋值,save操作

1
yield models.ContractGood.update({ contract_id: '22222' }, {where: {GUID: 1333170}, transaction: t})

涉及到更改主键,一定慎重

0%