Skip to content

Commit 93617a4

Browse files
authored
fix(zmodel): allow @db.Json and @db.JsonB attributes on typed-json fields (#2183)
1 parent 15b13f5 commit 93617a4

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/schema/src/res/stdlib.zmodel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ attribute @db.Timetz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
505505

506506
// Json type modifiers
507507

508-
attribute @db.Json() @@@targetField([JsonField]) @@@prisma
509-
attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
508+
attribute @db.Json() @@@targetField([JsonField, TypeDefField]) @@@prisma
509+
attribute @db.JsonB() @@@targetField([JsonField, TypeDefField]) @@@prisma
510510

511511
// Bytes type modifiers
512512

tests/integration/tests/enhancements/json/typing.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,37 @@ async function main() {
385385
}
386386
);
387387
});
388+
389+
it('supports @db.Json and @db.JsonB', async () => {
390+
await loadSchema(
391+
`
392+
type Profile {
393+
age Int @gt(0)
394+
}
395+
396+
model User {
397+
id Int @id @default(autoincrement())
398+
profile Profile @json @db.Json
399+
posts Post[]
400+
@@allow('all', true)
401+
}
402+
403+
type Meta {
404+
description String
405+
}
406+
407+
model Post {
408+
id Int @id @default(autoincrement())
409+
title String
410+
user User @relation(fields: [userId], references: [id])
411+
userId Int
412+
meta Meta @json @db.JsonB
413+
}
414+
`,
415+
{
416+
provider: 'postgresql',
417+
pushDb: false,
418+
}
419+
);
420+
});
388421
});

0 commit comments

Comments
 (0)