mikro-orm / mikro-orm

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases.
https://mikro-orm.io
MIT License
7.85k stars 548 forks source link

MikroORM doesn't delete orphans if they have custom type primary key #4033

Closed lsndr closed 1 year ago

lsndr commented 1 year ago

Describe the bug I have one to many relation. When I try to remove a child entity from parent's collection (removeOrphans set to true), it does nothing, since it improperly handles custom primary key type.

It runs the following query:

delete from child_entity where id in ('[object Object]')

To Reproduce Here is a repository with a reproduction test https://github.com/lsndr/mikroom-delete-1toM-bug

Expected behavior Child entities must be removed

Versions

Dependency Version
node ?
typescript ?
mikro-orm 5.6.8
your-driver ?
lsndr commented 1 year ago

At the same time it handles custom primary key types correctly when removeOrphans is set to false

B4nan commented 1 year ago

Thanks for the repro, looks valid.