Sergei Basharov
Sergei Basharov

Reputation: 53850

How to set Model id to a string in Loopback?

I have a string that can be used to uniquely identify a Model instance, e.g., email - [email protected], which can be assigned to only one instance in the database, which means it won't be duped.

Now, how can I make this string from a variable to be assigned to a newly created instance automatically on creation?

Upvotes: 1

Views: 605

Answers (1)

Sergei Basharov
Sergei Basharov

Reputation: 53850

I have just found it in the docs:

In database terms, ID properties are primary key column(s) are. Such properties are defined with the 'id' attribute set to true or a number as the position for a composite key.

{
    "myId": {
    "type": "string", 
    "id": true 
  }
}

Upvotes: 2

Related Questions