【问题标题】:how to get nested master-detail or master - detail -detail query in Loopback如何在 Loopback 中获取嵌套的 master-detail 或 master-detail-detail 查询
【发布时间】:2018-01-22 01:15:19
【问题描述】:

我有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'
    }
  });

更新

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


【解决方案1】:

我用谷歌搜索,我认为你必须深入了解https://loopback.io/doc/en/lb3/Include-filter.html

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多