我很新,節點和續集,我試圖按照這short introduction。爲什麼我的Model.find不返回任何內容?
我已經完成了連接到我的數據庫的部分(postgres)。我也定義了一個模型:
var User = sequelize.define('User', {
username: Sequelize.STRING,
password: Sequelize.STRING
});
我已經成功地同步了方案和創建的實例。但是,當我嘗試使用這個數據庫中讀取:
User
.find({ where: { username: 'john-doe' } })
.then(function(err, johnDoe) {
if (!johnDoe) {
console.log('No user with the username "john-doe" has been found.');
} else {
console.log('Hello ' + johnDoe.username + '!');
console.log('All attributes of john:', johnDoe.get());
}
});
該實例確實存在,但我只看到消息「與......沒有用戶」。它生成的查詢似乎是正確的,當我手動嘗試時,返回的結果是我期望看到的。
使用相同的查詢,我可以做到這一點,這也適用:
sequelize.query("SELECT * FROM my_user_table where username='john-doe'", { type: sequelize.QueryTypes.SELECT})
.then(function(items) {
// We don't need spread here, since only the results will be returned for select queries
console.log(items);
});
缺少什麼我在這裏?
Gotcha。非常感謝 –