0
votes

I am working with Loopback to automate the creation of REST APIs and using PostgreSQL as my datasource. I am a front-end developer with little experience in database schemas. I have a question about ID columns and how loopback works with databases.

I was given an SQL database that contains a table with the following fields:

typeId | techType | comments

When I try to do a GET request via the Loopback Explorer, I get an error that the request expects an 'id' column:

{
  "error": {
    "statusCode": 500,
    "name": "error",
    "message": "column \"id\" does not exist",
    "length": 102,
    "severity": "ERROR",
    "code": "42703",
    "position": "60",
    "file": "parse_relation.c",
    "line": "3293",
    "routine": "errorMissingColumn",
    "stack": "error: column \"id\" does not exist\n    at Connection.parse
       //...snip...
  }
}

Do I need to manually create an id field in my datasource or do I create the property on the client side via lb model CLI ? Or, other suggestions? What happens if I have hundreds of tables that may be without a vanilla'id' colum (they might be labeled differently)?

1

1 Answers

0
votes

According to the Loopback docs, I had to show that my custom id field typeId is my primary key like so:

"technologytypeid": {
  "type": "number",
  "id": true
}

That fixed the issue.