我试图使用Strongloop Loopback 4框架从模型中自动创建表。
我遇到的问题是模型属性都是小写的,即使它们是用camelCase定义的。
用户模型示例
@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"
}
现在我在package.json中使用他们的脚本调用migrate或使用automigrate()得到了相同的结果。如您所见,名字和姓氏被定义为firstName和lastName,但是在完成迁移时,它们被创建为firstname和lastname。有谁知道可能是什么问题?
找到它,如果有人在将来需要它。在@property对象中添加这样的属性。
@property({
postgresql: {
columnName: 'cammelCase', // it will be uppercased
},
})
如果有人知道更好的方式,请告诉我。