Skip to content

Models with primary keys not called id #486

Description

@ian-lewis-cs

Hi,

Loopback is pretty awesome but I am having a small problem defining a primary key in the model.

A lot of databases have primary keys which are not simply called 'id'.

I can't find any documentation which tells me how to handle this case with a model in loopback.

Basic example of table creation in mysql:

CREATE TABLE contact(
    contact_id INT(10) NOT NULL AUTO_INCREMENT,
    contact_name VARCHAR(50) NOT NULL,
    PRIMARY KEY(`contact_id`)
) ...

In the loopback model definition doing the following produces an additional, unwanted and unnecessary, key called 'id'.

"properties": {
    "contact_id": {
      "type": "number",
      "generated": true,
      "id":true,
      "required":false,
      "doc":"This is the primary ID used to identify a contact"
    },

From the API Explorer:

[
  {
    "contact_id": 0,
    "contact_name": "",
    "id": 0
  }
]

What changes need to be made to the JSON above to make the model comply with the DB design?

Many thanks,

Ian

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions