错误:缺少传递给findOrCreate的options参数中的where属性。

时间:2016-11-26 17:05:07

标签: javascript node.js sequelize.js

我尝试使用sequelize 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);
            });

1 个答案:

答案 0 :(得分:3)

 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);
        });