Skip to content

Commit

Permalink
fix(delegate): make sure concrete fields are included when a polymorp…
Browse files Browse the repository at this point in the history
…hic model field is included in deep nesting (#1524)
  • Loading branch information
ymc9 authored Jun 20, 2024
1 parent a14bf29 commit b34531d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/runtime/src/enhancements/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
92 changes: 92 additions & 0 deletions tests/regression/tests/issue-1522.test.ts
Original file line number Diff line number Diff line change
@@ -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',
});
});
});

0 comments on commit b34531d

Please sign in to comment.