我有category
和category_subs
,主细节模型,后期模型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'
}
});
更新
类别.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