strongloop有很多关系

时间:2015-05-28 15:53:37

标签: strongloop

我有一个Service模型,其中包含以下JSON定义:

公共/模型/ service.js

{
  "name": "service",
  ...
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "servicePrices": {
      "type": "hasMany",
      "model": "ServicePrice"
      "foreignKey": "serviceId"
    }
  },
  ...
}

我有第二个型号ServicePrice

公共/模型/服务price.js

{
  "name": "service_price",
  ...
  "properties": {
    "price": {
      "type": "number",
      "required": false
    }
  },
  "validations": [],
  "relations": {
    "service": {
      "type": "belongsTo",
      "model": "Service",
      "foreignKey": ""
    }
  },
  ...
}

我试图找回有效载荷,如下所示:

http://0.0.0.0:3000/api/services

[
  {
    "name": "Service-1",
    "id": 1,
    "servicePrices": [
      {"id": 1, "price": 10},
      {"id": 2, "price": 12}
    ]
  },
  {
    "name": "Service-2",
    "id": 2,
    "servicePrices": [
      {"id": 3, "price": 14},
      {"id": 4, "price": 16}
    ]
  }
]

我希望 - 在Strogloop Arc中迁移模型后 - 在service_price表中有一个额外的列(service_id)。但事实并非如此。并且 http://0.0.0.0:3000/api/services 会返回:

[
  {
    "name": "Service-1",
    "id": 1
  },
  {
    "name": "Service-2",
    "id": 2
  }
]

0 个答案:

没有答案