0
這將返回適量的記錄,但帳戶僅填充到第一條記錄中。查詢水線生成也是正確的,並返回每條記錄的所有相關數據。 populateAll()
沒有效果。交換.then
對於.exec
沒有任何影響。檢索多個記錄上的一對一關聯
此外,確實顯示爲關聯的一個「帳戶」甚至不是正確的記錄。
我做錯了什麼或這是一個錯誤?
mail_items.find().populate('account').then(function(mail_items) {
return mail_items;
});
accounts.js
module.exports = {
tableName : 'accounts',
attributes : {
account_id : {
type : 'int',
primaryKey : true,
unique : true
},
name : 'string'
}
};
mail_items.js
module.exports = {
tableName : 'mail_items',
attributes : {
mail_item_id : {
type : 'int',
primaryKey : true,
unique : true
},
sender : 'string',
account : {
columnName : 'account_id',
type : 'int',
model : 'accounts'
}
}
};
它的確工作。當然,每張桌子的pk不需要是id ...對嗎?如果沒有,我可以忍受它。 – brian 2014-10-07 09:19:44
是的,但帆是自動生成帶主鍵和自動遞增屬性的'ID'。 – vusan 2014-10-07 09:23:56
不填充模型的一個原因是,可能不存在使用mail_items鏈接的id的帳戶。 – vusan 2014-10-07 09:27:32