[英]how to get nested master-detail or master - detail -detail query in Loopback
我有category
和category_subs
,主从模型,post模型belongs to
category_subs。 在下面的代码,我可以得到两个主的细节,但我不知道如何将post
给他们,甚至attachment
后的远程方法的模型。
module.exports = function (Category) {
Category.categorySubs = function (id, cb) {
Category.find({
where: {
id: id
},
include: {
relation: 'categorySubs',
scope: {
include: 'category_subs'
}
}
},
function (err, posts) {
cb(null, posts);
});
}
Category.remoteMethod('categorySubs', {
accepts: {
arg: 'id',
type: 'string'
},
returns: {
arg: 'ID',
type: 'string'
},
http: {
path: '/iteminfo',
verb: 'get'
}
});
更新
category.json
"relations": {
"categorySubs": {
"type": "hasMany",
"model": "category_subs",
"foreignKey": "catgory_id"
}
},
category_subs
"relations": {
"posts": {
"type": "hasMany",
"model": "post",
"foreignKey": "category_sub_id"
}
},
我用谷歌搜索,我认为您必须深入了解https://loopback.io/doc/en/lb3/Include-filter.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.