-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Class/Model Name to Have A Different Name From the Database Table #2134
Comments
@shadyanwar , you can specify the model name that is different from the table name.
|
Worked like a charm! Thank you! |
This is a great suggestion. Would you @shadyanwar like to contribute this improvement yourself? Let's reopen this issue to keep track of this enhancement. |
@bajtos Sure. Could you please point to me where to look? I thought it would be https://github.com/strongloop/loopback-cli/blob/master/bin/loopback-cli.js |
@shadyanwar, the CLI code for LB4 can be found in the @bajtos @shadyanwar, I'm not sure if adding the database/table information as part of the |
Fair point. In LB4, it's possible to attach a single model to multiple datasources (databases). For long term, we may want to find a way how to specify the table name at repository level. At the moment, the only solution for customizing table name is to use database-specific model configuration as shown in #2134 (comment). As I am thinking about this more, I see a different problem: the table name is specific to a connector (e.g. So at the end, I am not sure what to change. I guess the best option is to enhance our model template with a comment showing users how to add custom configuration? The template in loopback-next/packages/cli/generators/model/templates/model.ts.ejs generates the following TypeScript code now: @model()
export class Customer extends Entity { Proposed new version: @model({
settings: {
// Configure model settings here, e.g. set a custom table name
// https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#data-source-specific-options
}
})
export class Customer extends Entity { @strongloop/loopback-maintainers thoughts? |
It seems like DB2 doesn't work in this way |
@model({
settings: {
db2: {
table: 'usage',
schema: 'att'
},
},
}) even I add code above I still get the same issue
I don't know why it always uses my user name SHAO as to be the schema but not att. |
@yueshaohui, I think you need to specify the |
Yes, Actually I have a schema configured in my DataSource, and everything running well as connecting DB2 in a general way. Thanks for your help following is the configuration in my DataSource
|
Description / Steps to reproduce / Feature proposal
Create/map a class/model with a name different from the name in its MySQL table
Current Behavior
If the class name is different, there is no way to map it to the correct table having a different name.
Expected Behavior
Just like individual properties inside the class, a class/model should be allowed to be exposed with a custom name different from that in the database table.
The text was updated successfully, but these errors were encountered: