Search code examples
loopback4

How to create loopback 4 model, repository and controller without specifying an ID


My model has a Composite Primary Key, composed by 3 columns. When I try to create everything using commands:

lb4 model
lb4 repository
lb4 controller

I can't find the way to specify those three camps combined are the PK, or to simply don't specify the id at all.

The first step I am forced to write an id is on the repository generator

When reaching lb4 controller step it forces me to specify an id again

I'm new using this framework, and tried to search more info about this but was unsuccessful.


Solution

  • Loopback4 doesn't support composite keys out of the box currently. You can read more here as well: https://github.com/strongloop/loopback-next/issues/1830 A work around would be to declare a primary key when you run lb4 model and then, in your find, use the where clause to specify another key as well. This, of course, doesnt enforce uniqueness, but again, there currently is no composite key support.