Loopbackjs查询通过REST API相关的模型
问题描述:
有没有什么办法来查询相关模型相关模型像post
\获取:Loopbackjs查询通过REST API相关的模型
{"order": "created_at DESC","include":[{"relation": "user"}]
但是,在我的user
模式存在的关系hasone
与settings
模型。我也想从post
\ Get rest api查询。我试过:
{ "include": { "relation": "user","include": {"relation":"settings"}}}
但没有运气。
答
我已经创建了与您的问题相关的嵌套关系。
例如: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
});
试试这个办法,希望这将有所帮助。
也许我对另一个问题的回答可以帮助你:https://stackoverflow.com/questions/45760175/multiple-includes-on-different-depths-in-a-loopback-node-js-query/45769344#45769344 –