From aaab890f91eaa5d51ae48e435cef2820074bdb91 Mon Sep 17 00:00:00 2001 From: Eugen Istoc Date: Tue, 10 Feb 2026 20:41:31 -0500 Subject: [PATCH 1/3] fix: enhance delegate model interaction with afterEntityMutation plugin support in child updates --- .../orm/src/client/crud/operations/base.ts | 6 ++- .../entity-mutation-hooks.test.ts | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/orm/src/client/crud/operations/base.ts b/packages/orm/src/client/crud/operations/base.ts index fc75cac9d..e02824039 100644 --- a/packages/orm/src/client/crud/operations/base.ts +++ b/packages/orm/src/client/crud/operations/base.ts @@ -1218,8 +1218,10 @@ export abstract class BaseOperationHandler { ); // only fields not consumed by base update will be used for this model finalData = baseUpdateResult.remainingFields; - // base update may change entity ids, update the filter - combinedWhere = baseUpdateResult.baseEntity; + // trim to id fields only to avoid "missing FROM-clause" errors in the child update + combinedWhere = baseUpdateResult.baseEntity + ? getIdValues(this.schema, modelDef.baseModel!, baseUpdateResult.baseEntity) + : baseUpdateResult.baseEntity; // update this entity with fields in updated base if (baseUpdateResult.baseEntity) { diff --git a/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts b/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts index eb8a25f16..a68e05204 100644 --- a/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts +++ b/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts @@ -691,4 +691,45 @@ describe('Entity mutation hooks tests', () => { await expect(client.user.findMany()).toResolveWithLength(0); }); }); + + describe('Delegate model interaction', () => { + it('update on child model succeeds with afterEntityMutation plugin', async () => { + const client = await createTestClient( + ` +model Base { + id Int @id @default(autoincrement()) + orgId Int + type String + @@delegate(type) +} + +model Child extends Base { + childField Int +} +`, + ); + + const withPlugin = client.$use({ + id: 'test', + onEntityMutation: { + afterEntityMutation() {}, + }, + }); + + const created = await withPlugin.child.create({ + data: { orgId: 1, childField: 10 }, + }); + + const updated = await withPlugin.child.update({ + where: { id: created.id }, + data: { orgId: 2, childField: 20 }, + }); + + expect(updated).toBeTruthy(); + expect(updated.orgId).toBe(2); + expect(updated.childField).toBe(20); + + await client.$disconnect(); + }); + }); }); From 53671ab848e48edd0fe86fd9bfe3f958ef66341b Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sun, 22 Feb 2026 06:36:31 -0500 Subject: [PATCH 2/3] chore: update comments --- packages/orm/src/client/crud/operations/base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/orm/src/client/crud/operations/base.ts b/packages/orm/src/client/crud/operations/base.ts index cd512fad5..0314bcf95 100644 --- a/packages/orm/src/client/crud/operations/base.ts +++ b/packages/orm/src/client/crud/operations/base.ts @@ -1228,7 +1228,7 @@ export abstract class BaseOperationHandler { ); // only fields not consumed by base update will be used for this model finalData = baseUpdateResult.remainingFields; - // trim to id fields only to avoid "missing FROM-clause" errors in the child update + // make sure to include only the id fields from the base entity in the final filter combinedWhere = baseUpdateResult.baseEntity ? getIdValues(this.schema, modelDef.baseModel!, baseUpdateResult.baseEntity) : baseUpdateResult.baseEntity; From d18f9b5226058322b46427952b0a58001b7b8140 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sun, 22 Feb 2026 06:58:11 -0500 Subject: [PATCH 3/3] fix: reorg test structure --- .../entity-mutation-hooks.test.ts | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts b/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts index a68e05204..ceb063fe8 100644 --- a/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts +++ b/tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts @@ -691,11 +691,13 @@ describe('Entity mutation hooks tests', () => { await expect(client.user.findMany()).toResolveWithLength(0); }); }); +}); - describe('Delegate model interaction', () => { - it('update on child model succeeds with afterEntityMutation plugin', async () => { - const client = await createTestClient( - ` +describe('Entity mutation hooks - delegate model interaction', () => { + it('update on child model succeeds with afterEntityMutation plugin', async () => { + console.log('RUNNING!!!!'); + const client = await createTestClient( + ` model Base { id Int @id @default(autoincrement()) orgId Int @@ -707,29 +709,28 @@ model Child extends Base { childField Int } `, - ); + ); - const withPlugin = client.$use({ - id: 'test', - onEntityMutation: { - afterEntityMutation() {}, - }, - }); + const withPlugin = client.$use({ + id: 'test', + onEntityMutation: { + afterEntityMutation() {}, + }, + }); - const created = await withPlugin.child.create({ - data: { orgId: 1, childField: 10 }, - }); + const created = await withPlugin.child.create({ + data: { orgId: 1, childField: 10 }, + }); - const updated = await withPlugin.child.update({ - where: { id: created.id }, - data: { orgId: 2, childField: 20 }, - }); + const updated = await withPlugin.child.update({ + where: { id: created.id }, + data: { orgId: 2, childField: 20 }, + }); - expect(updated).toBeTruthy(); - expect(updated.orgId).toBe(2); - expect(updated.childField).toBe(20); + expect(updated).toBeTruthy(); + expect(updated.orgId).toBe(2); + expect(updated.childField).toBe(20); - await client.$disconnect(); - }); + await client.$disconnect(); }); });