Discuss
/
JavaScript
/
想要更新数据,对查询到的实例调用save()方法
想要更新数据,对查询到的实例调用save()方法
Topic source我也是和你一样的代码,一样的错误提示。后来想起了findAll返回的是一个数组,然后代码改成如下就可以了。 for(let o of p){ o.gender = true; o.updatedAt = Date.now(); o.version ++; await o.save(); }
- 1
kb466
(async () => { var p = await Pet.findAll({ where: { name: 'Gaffey' } }); p.gender = true; p.updatedAt = Date.now(); p.version ++; await p.save(); })();
运行后显示如下错误: Executing (default): SELECT
id
,name
,gender
,birth
,createdAt
,updatedAt
,version
FROMpets
ASpet
WHEREpet
.na me
= 'Gaffey'; (node:3364) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: p.save is not a function (node:3364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.请问为什么,怎样解决这个问题?