Sebastian
Sebastian

Reputation: 4811

Define unique key strongloop model

How can i make the Unique key as a combination of 3 columns in loopback model The model structure is like

"properties": {
"year": {
  "type": "number",
  "required": true
},
"user_id": {
  "type": "number",
  "required": true
},
"leave_type_id": {
  "type": "number",
  "required": true
},
"total_days": {
  "type": "number",
  "required": true
}

},

And for me the year,User_id,leave_type_id combination is going to be a unique key . How can i mention that in the loop back model definition

Upvotes: 0

Views: 1364

Answers (1)

superkhau
superkhau

Reputation: 2781

Define multiple id properties on the field.

...
"user_id": {
  "id": 1, //add this
  "type": "number",
  "required": true
},
"leave_type_id": {
  "id": 2, //add this
  "type": "number",
  "required": true
},
...

See http://docs.strongloop.com/display/LB/Model+definition+JSON+file#ModeldefinitionJSONfile-CompositeIDs

Upvotes: 4

Related Questions