I am trying to auto-create table from the model using Strongloop Loopback 4 framework.
The issue that I have is that model properties are all lowercase even they are defined with camelCase.
User model example
@model({ name: 'users', settings: { strict: false }, excludeBaseProperties: ['password'] })
export class User extends Entity {
@property({
type: 'number',
id: true,
required: true,
generated: true,
})
id: number;
@property({
type: 'string',
required: true,
})
firstName: string;
@property({
type: 'string',
required: true,
})
lastName: string;
@property({
type: 'string',
required: true,
index: {
unique: true,
},
})
email: string;
@property({
type: 'string',
required: true,
index: {
unique: true,
},
})
username: string;
@property({
type: 'string',
required: true,
})
password: string;
[prop: string]: any;
constructor(data?: Partial<User>) {
super(data);
}
}
db.datasource.json
{
"name": "db",
"connector": "postgresql",
"url": "postgres://postgres:postgres@localhost:5432/test_db",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres",
"database": "test_db"
}
Now I got the same result with using their script in package.json called migrate or with using automigrate(). As you can see first name and last name are defined as firstName and lastName but when migration is done they are created as firstname and lastname. Does anyone know what could be the problem?
Found it, if someone needs this in the future. In the @property object add a property like this.
@property({
postgresql: {
columnName: 'cammelCase', // it will be uppercased
},
})
If someone knows a better way please let me know.