0

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

Sebastian
  • 4,625
  • 17
  • 76
  • 145

1 Answers1

4

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

superkhau
  • 2,781
  • 18
  • 9