【问题标题】:Error: Missing where attribute in the options parameter passed to findOrCreate.错误:传递给 findOrCreate 的选项参数中缺少 where 属性。
【发布时间】:2016-11-26 17:05:06
【问题描述】:

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

【问题讨论】:

    标签: javascript node.js sequelize.js


    【解决方案1】:
     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);
            });
    

    【讨论】:

    • User.findOrCreate({ where: { email: profile.emails[0].value } }, { email: profile.emails[0].value, username: profile.displayName, token: token }) .then(user => { console.log(user) return user; }).catch(error => console.log(error))
    猜你喜欢
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 2018-02-14
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 2018-03-12
    相关资源
    最近更新 更多