Strongloop PostgreSQL 连接器嵌入式模型错误

Strongloop PostgreSQL connector embedded model error

获得了一个简单的环回 API 以使用 postgreSQL 连接器检索票证和响应。票证和回复单独返回正常,但当我尝试将回复嵌入票证模型时,出现以下错误。我已经尝试按照文档进行操作,并且我确信在我的一个关系中我缺少一些简单的东西但是无论我尝试什么,我都无法让它工作。

如有任何帮助,我们将不胜感激。

https://docs.strongloop.com/display/public/LB/Embedded+models+and+relations#Embeddedmodelsandrelations-EmbedsMany

门票型号:

{
"name": "Ticket",          
"base": "PersistedModel",
"idInjection": true,
"options": {
    "postgresql": {
        "schema": "customer_service",
        "table": "tbl_ticket"
     }
},
"properties": {
    "description": {
      "type": "String",
      "required": true,
      "length": null,
      "precision": null,
      "scale": null,
      "postgresql": {
        "columnName": "description",
        "dataType": "text",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "NO"
      }
    },    
    "id": {
      "type": "Number",
      "id": 1,
      "required": true,
      "length": null,
      "precision": 32,
      "scale": 0,
      "postgresql": {
        "columnName": "id",
        "dataType": "integer",
        "dataLength": null,
        "dataPrecision": 32,
        "dataScale": 0,
        "nullable": "NO"
      }
    }
  },
  "validations": [],
  "relations": {
    "responses": {
      "type": "embedsMany",
      "model": "Response",
      "property": "embededResponses",
      "options": {
        "validate": true,
        "forceId": false
      }   
    }
  },
  "acls": [],
  "methods": {}
}

响应模型:

{
  "name": "Response",
  "base": "PersistedModel",
  "idInjection": true,  
  "options": {
    "postgresql": {
      "schema": "customer_service",
      "table": "tbl_response"
    }
  },
  "properties": {
    "notes": {
      "type": "String",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "postgresql": {
        "columnName": "notes",
        "dataType": "text",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "YES"
      }
    },
    "ticketId": {
      "type": "Number",
      "required": true,
      "length": null,
      "precision": 32,
      "scale": 0,
      "postgresql": {
        "columnName": "ticket_id",
        "dataType": "integer",
        "dataLength": null,
        "dataPrecision": 32,
        "dataScale": 0,
        "nullable": "NO"
      }
    },
    "id": {
      "type": "Number",
      "id": 1,
      "required": true,
      "length": null,
      "precision": 32,
      "scale": 0,
      "postgresql": {
        "columnName": "id",
        "dataType": "integer",
        "dataLength": null,
        "dataPrecision": 32,
        "dataScale": 0,
        "nullable": "NO"
      }
    }
  },
  "validations": [],
  "relations": {
    "ticket": {
      "type": "belongsTo",
      "model": "Ticket",
      "foreignKey": "ticketId"
    }
  },
  "acls": [],
  "methods": {}
}

错误:

{  
    "error": {
      "name": "error",
      "status": 500,
      "message": "column \"embededresponses\" does not exist",
      "length": 126,
      "severity": "ERROR",
      "code": "42703",
      "position": "213",
      "file": ".\src\backend\parser\parse_expr.c",
      "line": "766",
      "routine": "transformColumnRef",
      "stack": "error: column \"embededresponses\" does not exist\n    at Connection.parseE (C:\WebApp\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:539:11)\n    at Connection.parseMessage (C:\WebApp\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:366:17)\n    at Socket.<anonymous> (C:\WebApp\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:105:22)\n    at Socket.emit (events.js:107:17)\n    at readableAddChunk (_stream_readable.js:163:16)\n    at Socket.Readable.push (_stream_readable.js:126:10)\n    at TCP.onread (net.js:538:20)"
    }
}

您的 Ticket 模型应具有以下关系部分:

"relations": {
    "Responses": {
      "type": "hasMany",
      "model": "Response",
      "foreignKey": "ticketId"
    }
  }

您的 Response 模型关系是正确的。

文档中不是很清楚嵌入关系是针对 NoSQL 数据库的。对于传统的 SQL 数据库,使用 Has* 关系类型。

要从 REST API 中检索带有 ResponsesTicket,请使用包含过滤器:https://docs.strongloop.com/display/public/LB/Include+filter

示例:localhost:3000/api/Tickets/{id}?filter[include]=responses

我听说您 可以 使用与 SQL 数据源的嵌入式关系,但数据随后以字符串化-JSON 格式存储。

我在 https://docs.strongloop.com/display/LB/Embedded+models+and+relations 中添加了备注。

兰特