![](/img/trans.png)
[英]SailsJS | TypeError: Cannot read property 'then' of undefined
[英]Error in SailsJs. TypeError: Cannot read property 'attributes' of undefined
我正在使用sailsjs和mongodb。 我收到錯誤“ TypeError:無法讀取未定義的屬性'attributes'”。
這些是模型:
UserInterest.js
module.exports = {
attributes: {
id: {
type: 'integer',
primaryKey: true
},
name: { type: 'string' },
profiles: { collection: 'UserProfile', via: 'interests'}
}
};
UserProfile.js
module.exports = {
attributes : {
id : {
type : 'string',
autoIncrement : true,
primaryKey : true
},
createdAt : {
type : 'datetime'
},
updatedAt : {
type : 'datetime'
},
user : {
model : 'User'
},
sex : {
type : 'integer'
},
interests : {
collection : "UserInterest",
via : "profiles",
dominant : true
}
//Other attributes here
}
};
我正在嘗試以這種方式加載用戶個人資料:
UserProfile.findOne({user : id})
.populate("interests")
.exec(function(err, obj) {
if (err) {
cb(err, null);
} else {
cb(err, obj);
}
});
該錯誤發生在填充函數中。 為什么會這樣呢?
在為這個問題苦苦掙扎之后,我找到了答案。 屬性興趣重復,並且Sails遇到了問題。 我消除了重復項,保留了集合定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.