0
votes

can a loopback model generate a unique ID. Right now I have a auto increment column in a mysql table but then the app sends a insrt query to mysql and then queries it back to get the unique ID. Can loopback just pick a unique ID to insert? If so, how does it now that that ID is unique in the database table?

1

1 Answers

4
votes

You can define idInjection in your model

{
  "name":"ModelName",
  ....
  "options":{
      "idInjection": true
  }
  ....
  "properties":{
      "name":"id",
      "id":1,
  ....

Then just do nothing to your ID column in the create statement and it will be automatically inserted and incremented.