Loopback:嵌套关系,在查询中获取父级

时间:2017-08-29 20:00:08

标签: api loopback

所以我有这个场景

模型: - 比赛 - 比赛季节 - 匹配

竞赛季节:

  "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

1 个答案:

答案 0 :(得分:0)

我自己搞定了!

    import pyhs2
    with pyhs2.connect(host='localhost',
           port=10000,
           authMechanism="PLAIN",
           user='your_user',
           password='your_password',
           database='your_default_db') as conn:
        with conn.cursor() as cur:
            print cur.getDatabases()
            cur.execute("select * from table")
            #Return info from query
            print cur.getSchema()

示例:enter link description here

oughta love loopback