diff --git a/packages/runtime/src/enhancements/delegate.ts b/packages/runtime/src/enhancements/delegate.ts index ea31fe02d..579dc31c6 100644 --- a/packages/runtime/src/enhancements/delegate.ts +++ b/packages/runtime/src/enhancements/delegate.ts @@ -194,15 +194,13 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler { if (this.injectBaseFieldSelect(model, field, value, args, kind)) { delete args[kind][field]; - } else { - if (fieldInfo && this.isDelegateOrDescendantOfDelegate(fieldInfo.type)) { - let nextValue = value; - if (nextValue === true) { - // make sure the payload is an object - args[kind][field] = nextValue = {}; - } - this.injectSelectIncludeHierarchy(fieldInfo.type, nextValue); + } else if (fieldInfo.isDataModel) { + let nextValue = value; + if (nextValue === true) { + // make sure the payload is an object + args[kind][field] = nextValue = {}; } + this.injectSelectIncludeHierarchy(fieldInfo.type, nextValue); } } } diff --git a/tests/regression/tests/issue-1522.test.ts b/tests/regression/tests/issue-1522.test.ts new file mode 100644 index 000000000..bc6a9fb34 --- /dev/null +++ b/tests/regression/tests/issue-1522.test.ts @@ -0,0 +1,92 @@ +import { loadSchema } from '@zenstackhq/testtools'; +describe('issue 1522', () => { + it('regression', async () => { + const { enhance } = await loadSchema( + ` + model Course { + id String @id @default(uuid()) + title String + description String + sections Section[] + activities Activity[] + @@allow('all', true) + } + + model Section { + id String @id @default(uuid()) + title String + courseId String + idx Int @default(0) + course Course @relation(fields: [courseId], references: [id]) + activities Activity[] + } + + model Activity { + id String @id @default(uuid()) + title String + courseId String + sectionId String + idx Int @default(0) + type String + course Course @relation(fields: [courseId], references: [id]) + section Section @relation(fields: [sectionId], references: [id]) + @@delegate(type) + } + + model UrlActivity extends Activity { + url String + } + + model TaskActivity extends Activity { + description String + } + `, + { enhancements: ['delegate'] } + ); + + const db = enhance(); + const course = await db.course.create({ + data: { + title: 'Test Course', + description: 'Description of course', + sections: { + create: { + id: '00000000-0000-0000-0000-000000000002', + title: 'Test Section', + idx: 0, + }, + }, + }, + include: { + sections: true, + }, + }); + + const section = course.sections[0]; + await db.taskActivity.create({ + data: { + title: 'Test Activity', + description: 'Description of task', + idx: 0, + courseId: course.id, + sectionId: section.id, + }, + }); + + const found = await db.course.findFirst({ + where: { id: course.id }, + include: { + sections: { + orderBy: { idx: 'asc' }, + include: { + activities: { orderBy: { idx: 'asc' } }, + }, + }, + }, + }); + + expect(found.sections[0].activities[0]).toMatchObject({ + description: 'Description of task', + }); + }); +});