mikro-orm: PK columnType 'bigint' throws invalid type error for string when using QueryBuilder
Describe the bug I’m using MariaDB. The PK is columnType ‘bigint’ (auto-increment), the entity uses type string, which I would prefer.
EntityValidator.validateProperty() throws:
ValidationError: Trying to set Object.id of type 'string' to '1' of type 'number'
Stack trace
Trying to set Object.id of type 'string' to '1' of type 'number' - {
stack: [
"ValidationError: Trying to set Object.id of type 'string' to '1' of type 'number'\n" +
' at Function.fromWrongPropertyType (/usr/src/app/node_modules/@mikro-orm/core/errors.js:22:16)\n' +
' at EntityValidator.validateProperty (/usr/src/app/node_modules/@mikro-orm/core/entity/EntityValidator.js:62:44)\n' +
' at /usr/src/app/node_modules/@mikro-orm/core/EntityManager.js:473:42\n' +
' at Array.forEach (<anonymous>)\n' +
' at SqlEntityManager.map (/usr/src/app/node_modules/@mikro-orm/core/EntityManager.js:470:27)\n' +
' at /usr/src/app/node_modules/@mikro-orm/knex/query/QueryBuilder.js:411:37\n' +
' at Array.map (<anonymous>)\n' +
' at QueryBuilder.getResultList (/usr/src/app/node_modules/@mikro-orm/knex/query/QueryBuilder.js:411:20)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)'
]
}
To Reproduce Steps to reproduce the behavior:
- Create entity with
@PrimaryKey({ columnType: 'bigint' })
@Entity()
export class TblTest {
@PrimaryKey({ columnType: 'bigint' })
id!: string;
}
- Run as QueryBuilder select query
const qb = em.qb(TblTest)
await qb.select('*')
Expected behavior EntityValidator.validateProperty() to accept string type for ‘bigint’ columnType on MySQL/MariaDB db.
Additional context
It does work if I change the type id!: number;
Versions
“@mikro-orm/cli”: “^5.3.1”, “@mikro-orm/core”: “^5.3.1”, “@mikro-orm/mariadb”: “^5.3.1”, “@mikro-orm/nestjs”: “^5.1.1”, “typescript”: "^4.3.5
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (8 by maintainers)
You can override anything via
driverOptions, it will be merged with the object that is passed to theknexfunction.This is handled already:
https://github.com/mikro-orm/mikro-orm/blob/master/packages/mariadb/src/MariaDbConnection.ts#L39-L40