You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given we have a relationship of Many-to-Many: A Company has many ProductEntity's , and a ProductEntity may belong to many Company's
And the associations were defined using entity schemas
And There is a custom pivot entity called CompanyProduct
When we create a new Company and add a new Product to its collection
Then MikroORM throws an error: InvalidFieldNameException: insert into "test"."company_product" ("company_id", "product_entity_id") values ('1', '1') returning "id" - column "product_entity_id" of relation "company_product" does not exist
Full Stack trace:
src/mikro-orm.test.ts > Mikro Orm > creates a company with products
InvalidFieldNameException: insert into "test"."company_product" ("company_id", "product_entity_id") values ('1', '1') returning "id" - column "product_entity_id" of relation "company_product" does not exist
❯ PostgreSqlExceptionConverter.convertException node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:36:24
❯ PostgreSqlDriver.convertException node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:201:54
❯ node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:205:24
❯ PostgreSqlDriver.nativeInsertMany node_modules/@mikro-orm/knex/AbstractSqlDriver.js:300:21
❯ PostgreSqlDriver.updateCollectionDiff node_modules/@mikro-orm/knex/AbstractSqlDriver.js:742:13
❯ UnitOfWork.persistToDatabase node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:715:13
❯ PostgreSqlConnection.transactional node_modules/@mikro-orm/knex/AbstractSqlConnection.js:36:25
❯ UnitOfWork.doCommit node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:295:17
❯ UnitOfWork.commit node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:268:13
❯ Parser.parseErrorMessage node_modules/pg-protocol/src/parser.ts:369:69
❯ Parser.handlePacket node_modules/pg-protocol/src/parser.ts:188:21
❯ Parser.parse node_modules/pg-protocol/src/parser.ts:103:30
While the issue is valid, the repro won't work after the fix on its own - you can't use onCreate property option for pivot entities here, working with the M:N relation does not create such entity instances under the hood, so they won't be executed. You need a db default (defaultRaw: 'current_timestamp'), and similarly, pivot rows are never updated, only added or removed, so the onUpdate will only work if you manually load that pivot entity and modify it.
edit: and of course the fix itself is not enough for v5, there is some weird issue with the discovery apparenlty
edit2: actually nope, it's just the EntitySchema type not being strict enough which is already addressed in v6 luckily, ported to 5.x branch too
Describe the bug
Company
has manyProductEntity
's , and aProductEntity
may belong to manyCompany
'sCompanyProduct
Company
and add a newProduct
to its collectionInvalidFieldNameException: insert into "test"."company_product" ("company_id", "product_entity_id") values ('1', '1') returning "id" - column "product_entity_id" of relation "company_product" does not exist
Full Stack trace:
Reproduction
yarn
docker compose up -d
yarn test
What driver are you using?
@mikro-orm/postgresql
MikroORM version
5.9.4
Node.js version
20.9.0
Operating system
WSL 2.0
Validations
The text was updated successfully, but these errors were encountered: