Property name in model
Hi all,
I am trying to give a property column name in the database different from its name in the class, I tried the code below to store the value as user_id instead of id in the database:
class User { @property({name: 'user_id'}) id: string }
But it seems the name attribute in the @property is being ignored. I also tried to use the store but no success: @property({ type: 'string', store: {in: true, out: true, name: 'user_id'}, })
Just wondering is there is alternative way for setting the name of the column in the database.
Many thanks,
According to the connector and the database you have to define the model in the following way ...
Example with mysql:
@property({
type: 'date',
mysql: {
columnName: 'created_at'
}
})
createdAt?: string;
I have the same issue, but is with properties with type different than object
@model({name: 'bidding', settings: {postgresql: {schema: 'core_bidding'}}})
export class Bidding extends Entity {
@property({
type: 'string',
required: true,
id: true,
postgres: {
columnName: 'bidding_cd'
},
})
code: string;
@property({
type: 'string',
required: false,
postgres: {
columnName: 'bidding_name'
},
})
name?: string;
}
generated this error:
Try http://127.0.0.1:3000/ping
loopback:connector:postgresql Settings {"name":"OpenData","connector":"postgresql","host":"localhost","port":5432,"user":"XXX","password":"#XXX","database":"XXX","debug":false} +0ms
loopback:connector:postgresql SQL: SELECT "code","bidding_description_search" FROM "core_bidding"."bidding" ORDER BY "code" +197ms
loopback:connector:postgresql error: no existe la columna «code»
I'm using:
"dependencies": {
"@loopback/boot": "^1.2.1",
"@loopback/context": "^1.11.0",
"@loopback/core": "^1.4.1",
"@loopback/openapi-v3": "^1.3.5",
"@loopback/repository": "^1.4.1",
"@loopback/rest": "^1.10.2",
"@loopback/rest-explorer": "^1.1.16",
"@loopback/service-proxy": "^1.0.8",
"loopback-connector-postgresql": "^3.6.1",
"loopback-connector-rest": "^3.4.1"
},
Best Regards
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
Tengo el mismo problema, pero es con propiedades con un tipo diferente al objeto
@model({name: 'bidding', settings: {postgresql: {schema: 'core_bidding'}}}) export class Bidding extends Entity { @property({ type: 'string', required: true, id: true, postgres: { columnName: 'bidding_cd' }, }) code: string; @property({ type: 'string', required: false, postgres: { columnName: 'bidding_name' }, }) name?: string; }generó este error:
Try http://127.0.0.1:3000/ping loopback:connector:postgresql Settings {"name":"OpenData","connector":"postgresql","host":"localhost","port":5432,"user":"XXX","password":"#XXX","database":"XXX","debug":false} +0ms loopback:connector:postgresql SQL: SELECT "code","bidding_description_search" FROM "core_bidding"."bidding" ORDER BY "code" +197ms loopback:connector:postgresql error: no existe la columna «code»Estoy usando:
"dependencies": { "@loopback/boot": "^1.2.1", "@loopback/context": "^1.11.0", "@loopback/core": "^1.4.1", "@loopback/openapi-v3": "^1.3.5", "@loopback/repository": "^1.4.1", "@loopback/rest": "^1.10.2", "@loopback/rest-explorer": "^1.1.16", "@loopback/service-proxy": "^1.0.8", "loopback-connector-postgresql": "^3.6.1", "loopback-connector-rest": "^3.4.1" },Atentamente
other solution
@property({
name: 'bidding_cd'
type: 'string',
required: true,
id: true,
})
code: string;