我有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'
}
});
更新
category.json
"relations": {
"categorySubs": {
"type": "hasMany",
"model": "category_subs",
"foreignKey": "catgory_id"
}
},
category_subs
"relations": {
"posts": {
"type": "hasMany",
"model": "post",
"foreignKey": "category_sub_id"
}
},