我有多个模型合作伙伴, PartnerUsers , ContentRequest 和 UserContents 。
协会就像
// Association between Partner & PartnerUsers
m.Partners.hasMany(m.PartnerUsers);
m.PartnerUsers.belongsTo(m.Partners);
// Association between PartnerUsers & UserContents
m.PartnerUsers.hasMany(m.UserContents);
m.UserContents.belongsTo(m.PartnerUsers);
// Association between Partner & ContentRequests
m.Partners.hasMany(m.ContentRequests);
m.ContentRequests.belongsTo(m.Partners);
现在我正在使用急切的加载,我不知道如何使用多个预先加载。 我这样做
Partner.find(
where: {
id: id
},
include: [PartnerContents, ContentRequests],
include: [{
model: PartnerUsers,
include: [UserContents]
}]
)
.success(function(partner){
})
但是没有给我 partner.partnerContents& partner.contentRequests
我有** patner.partnerUsers [0] .userContents **
如果我这样做的话
Partner.find(
where: {
id: id
},
include: [PartnerContents]
//include: [{
// model: PartnerUsers,
// include: [UserContents]
// }]
)
.success(function(partner){
})
我有 patner.partnerContents
建议我如何通过协会获得所有三个,例如 patner.partnerContents,patner.contentRequests和patner.partnerUsers [0] .userContents
答案 0 :(得分:2)
请参阅documentation options.include
检查一下:
Partner.find({
where: {
id: id
},
include: [
PartnerContents,
ContentRequests,
{
model: PartnerUsers,
include: [UserContents]
}
]})
.success(function(partner) {
});