Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the mysql table name for a model on loopback 4?

I know that by default loopback 4 infers the name of the mysql database table from the model class or repository class. How can I set the table name to a custom string value? Probably I have to use a decorator, I have not been able to find anything in the documentation. Thanks.

like image 414
Juan Pablo Fernandez Avatar asked Oct 15 '18 18:10

Juan Pablo Fernandez


People also ask

What are models in LoopBack?

A LoopBack model is a JavaScript object with both Node and REST APIs that represents data in backend systems such as databases. Models are connected to backend systems via data sources. You use the model APIs to interact with the data source to which it is attached.

What is loopback4?

LoopBack is an award-winning, highly extensible, open-source Node. js and TypeScript framework based on Express. It enables you to quickly create APIs and microservices composed from backend systems such as databases and SOAP or REST services.


1 Answers

In your decorator @model, just add the property name and it will work! For example:

@model({
  name: 'sales_order'
})
export class Order extends Entity{
...
}
like image 51
hanego Avatar answered Oct 11 '22 20:10

hanego