如何在环回中获取嵌套的主-细节或主-细节-细节查询



我有categorycategory_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

最新更新