2016-11-26 81 views
0

我試圖使用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); 
      }); 

回答

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