-
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
ID automatically generated by PostgreSQL becomes undefined #4751
Comments
@raw-ham Hi, the model definition looks legit to me. I think the problem is caused by id auto-generation. Could you check what's your default value for the identifier of table
If the id property in your table is not autogenerated (e.g default value of identifier is const test = await this.testTableRepository.create({testContent: "test"}); will be There are three ways to fix it:
ALTER the Define your model first, then use @model()
export class testTable extends Entity {
@property({
type: 'number',
id: true,
required: false // not necessary, but it cannot be true
generated: true, // this will set the default value of the identifier for you
postgresql: { // this setting allows you to have different names for model and db column
columnName: 'testid', // this needs to be in lowercase
dataType: 'integer',
dataLength: null,
dataPrecision: null,
dataScale: 0,
nullable: 'NO',
},
})
testId?: number;
// other props..
constructor(data?: Partial<TestTable>) {
super(data);
}
} |
@agnes512 Thanks for your answer
I can't do either fix. No problem occurs if the DB column name is lowercase or snake case. I think the problem is that Or is there a restriction that ID columns can only be used in lowercase or snakecase? I use Google Translate. |
@raw-ham I can reproduce the issue, and it only happens in Postgres. I think it's still because of the identifier issue. And weird thing is that the workaround doesn't work anymore D: (workaround: export class TestTable extends Entity {
@property({
type: 'number',
required: false,
scale: 0,
id: 1,
postgresql: {
columnName: 'testId',
dataType: 'bigint',
dataLength: null,
dataPrecision: null,
dataScale: 0,
nullable: 'NO',
},
})
testid: number; // in lowercase
... ) The only way to make it work now is to set the identifier column name to lowercase for Postgres, which seems a unpleasant bug to me. issue #3343 is for column name mapping. It doesn't solve this specific issue in Postgres. I will discuss with the team and hopefully fix it soon. Thanks for reporting the bug! |
Yes, there is no other solution. So I am in trouble.
Thank you very much! Please comment if you need more information. |
Debug note: |
For code change in |
@raw-ham a fix is released in
Could you try it out to see if it works on your end? thanks |
I confirmed that it was solved in my project. Thank you for correspondence! |
A situation similar to #3749
Steps to reproduce
lb4 datasource
lb4 discover
lb4 repository
lb4 controller
Current Behavior
Do the following
Result
The instance is being created in the database, but it somehow failed to map to the property.
Expected Behavior
I want it to look like the following
Additional information
The following is a guess
I think the problem is that it is
toLowerCase()
in the function here.https://github.com/strongloop/loopback-connector-postgresql/blob/v3.9.0/lib/postgresql.js#L369
After rewriting as below, it worked.
PostgreSQL.prototype.getInsertedId
https://github.com/strongloop/loopback-connector-postgresql/blob/v3.9.0/lib/postgresql.js#L553
SQLConnector.prototype.idColumn
https://github.com/strongloop/loopback-connector/blob/v4.4.0/lib/sql.js#L423
PostgreSQL.prototype.dbName
https://github.com/strongloop/loopback-connector-postgresql/blob/v3.9.0/lib/postgresql.js#L369
lb4 --version
Related Issues
Acceptance Criteria
The text was updated successfully, but these errors were encountered: