有没有办法查询相关模型的相关模型,例如来自post
\ Get:
{"order": "created_at DESC","include":[{"relation": "user"}]
但是,在我的user
模型中,存在hasone
与settings
模型的关系。我也希望得到它,同时查询post
\获取休息api。我试过了:
{ "include": { "relation": "user","include": {"relation":"settings"}}}
但没有运气。
答案 0 :(得分:0)
我创建了与您的问题相关的嵌套关系。
示例:teamRole.json
TeamRole> belongsTo>用户和团队
"validations": [],
"relations": {
"team": {
"type": "belongsTo",
"model": "Team",
"foreignKey": ""
},
"user": {
"type": "belongsTo",
"model": "User",
"foreignKey": ""
}
}
检索结果
app.models.TeamRole.findOne({
where: {
userId: user.id
},
include:[ {
relation: 'team'
},
{
relation: 'user'
} ]
},function(err,team,user){
//retrieve relational data here
});
尝试这种方法,希望这会有所帮助。