如何定义一个模型在Strongloop Loopback中有许多相同的模型?

时间:2014-06-11 14:11:44

标签: node.js loopbackjs

当我想定义一个组织有很多组织时,models.json应该是什么样的?

我尝试通过relationshio定义一个hasMany,使用一个名为clients的中间模型,但它没有工作:

"organization": {
  "properties": {
    "name": {
      "type": "string"
    }
  },
  "relations": {
    "clients": {
      "type": "hasMany",
      "model": "organization",
      "foreignKey": "clientId",
      "through": "client"
    }
  }
  "client": {
    "properties": {
      "organizationId": {
        "type": "number",
        "id": true
      },
      "clientId": {
        "type": "number",
        "id": true
      }
    },
    "relations": {
      "organization": {
        "type": "belongsTo",
        "model": "organization",
        "foreignKey": "organizationId"
      },
      "client": {
        "type": "belongsTo",
        "model": "organization",
        "foreignKey": "clientId"
      }
    }
  }

1 个答案:

答案 0 :(得分:2)