错误:缺少选项参数中的属性传递给findOrCreate。
问题描述:
我试图使用sequelize findOrCreate功能,但我发现了这个错误:错误:缺少选项参数中的属性传递给findOrCreate。
Error: Missing where attribute in the options parameter passed to findOrCreate.
这是我的代码:
var values = { slack_id: profile.id, name: profile.user };
var selector = { where: { slack_id: profile.id } };
User.findOrCreate(values, selector)
.then(function() {
return done(err, user);
});
答
Missing where attribute in the options parameter passed to
findOrCreate. Please note that the API has changed, and is now options
only (an object with where, defaults keys, transaction etc.)
你应该切换参数,以便在包含where子句的对象是第一个,而不是第二个。第二个参数是默认键的位置。
User.findOrCreate(selector, values)
.then(function() {
return done(err, user);
});