How can I set the mysql table name for a model on loopback 4?
In your decorator @model
, just add the property name and it will work!
For example:
@model({
name: 'sales_order'
})
export class Order extends Entity{
...
}
In LB4 this is the cleanest approach for mapping a model to a DB table when their respective names differ. I found this LB4 issue stating that the LB3 "options" model syntax is not supported and provides an example similar to what I provided below: https://github.com/strongloop/loopback-next/issues/2134
For example let's say your Entity class is named Person and its data lives in DB table named Contacts. Specify the db table in the model definition using the LB4 model syntax -
@model({
settings: {
mysql: {
schema: YOURSCHEMA,
table: "Contacts"
}
}
})
export class Person extends Entity {...}
This snippet is from a working example that uses a MySql db.