续集错误 - "model.get is not a function"



我已经使用graphql/sequelize/postgres/react创建了一个基本的CRUD Web应用程序。以下代码是在我的API中的续集解析器中,并且通过我的react.js frontend从GraphQl查询进行调用。

let profile = await Profile.find({where: { userId: args.userId }})
profile = await Profile.update(args, {where: { userId: args.userId }})
return profile.get({ plain: true })

如果我在对object.update和object的调用之间添加了一个附加对象。

let profile = await Profile.find({where: { userId: args.userId }})
profile = await Profile.update(args, {where: { userId: args.userId }})
profile = await Profile.find({where: { userId: args.userId }})
return profile.get({ plain: true })

为什么我会遇到此错误,如何在不添加其他呼叫的情况下消除它。

我的第一个答案不好。

如果您要更新并返回平面jane对象,请使用以下方式:

let profile = await Profile.findById(args.userId);
await profile.update(args);
return profile.toJSON();

" get"方法返回一个字段值,不确定这是您想做的。

来自文档:

instance.field
// is the same as
instance.get('field')
// is the same as
instance.getDataValue('field')

相关内容

最新更新