Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/runtime/src/enhancements/nested-write-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,14 @@ export class NestedWriteVisitor {
}

if (fieldInfo.isDataModel) {
// recurse into nested payloads
for (const [subAction, subData] of Object.entries<any>(payload[field])) {
if (this.isPrismaWriteAction(subAction) && subData) {
await this.doVisit(fieldInfo.type, subAction, subData, payload[field], fieldInfo, [
...nestingPath,
]);
if (payload[field]) {
// recurse into nested payloads
for (const [subAction, subData] of Object.entries<any>(payload[field])) {
if (this.isPrismaWriteAction(subAction) && subData) {
await this.doVisit(fieldInfo.type, subAction, subData, payload[field], fieldInfo, [
...nestingPath,
]);
}
}
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime/src/enhancements/policy/policy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ export class PolicyUtil {
) {
// multi-field unique constraint, flatten it
delete args[field];
for (const [f, v] of Object.entries(value)) {
args[f] = v;
if (value) {
for (const [f, v] of Object.entries(value)) {
args[f] = v;
}
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/integration/tests/regression/issue-765.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { loadSchema } from '@zenstackhq/testtools';

describe('Regression: issue 765', () => {
it('regression', async () => {
const { enhance } = await loadSchema(
`
model User {
id Int @id @default(autoincrement())
name String

post Post? @relation(fields: [postId], references: [id])
postId Int?

@@allow('all', true)
}

model Post {
id Int @id @default(autoincrement())
title String
User User[]

@@allow('all', true)
}
`
);

const db = enhance();
const r = await db.user.create({
data: {
name: 'Me',
post: undefined,
},
});
expect(r.name).toBe('Me');
expect(r.post).toBeUndefined();
});
});