【问题标题】:Loopback: nested relations, get parent in queryLoopback:嵌套关系,在查询中获取父级
【发布时间】:2017-08-30 04:10:09
【问题描述】:

所以我有这个场景

型号: - 竞赛 - 比赛赛季 - 匹配

比赛赛季在哪里:

  "relations": {
    "matches": {
      "type": "hasMany",
      "model": "match",
      "foreignKey": "competition-seasonId"
    },
    "competition": {
      "type": "belongsTo",
      "model": "competition",
      "foreignKey": ""
    }
  }

并且匹配有:

"relations": {
    "competition-season": {
      "type": "belongsTo",
      "model": "competition-season",
      "foreignKey": ""
    }
}

我要做的是在列出比赛时获取比赛对象,但是这样做

{
  include: ['competition-season']
}

现在我只是

[
  {
    id: 'xxxx',
    competition-seasonId: 'yyyy',
    competition-season: {
      competitionId: 'zzzz'
    }
  }
]

所以想得到比赛对象,而不仅仅是id

【问题讨论】:

    标签: api loopback


    【解决方案1】:

    我自己想出来的!

    include: [
      {
        relation: 'competition-season',
        scope: {
          include: 'competition'
        }
      }
    ]
    

    此处的示例:enter link description here

    应该爱回环

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      相关资源
      最近更新 更多