【发布时间】:2018-01-22 01:15:19
【问题描述】:
我有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"
}
},
【问题讨论】:
-
能否将相关模型关系添加到问题主体中?
标签: javascript node.js mongodb loopbackjs loopback