-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: model meta generator doesn't correctly identify relation names (#…
- Loading branch information
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
import { randomBytes } from 'crypto'; | ||
|
||
describe('issue 1241', () => { | ||
it('regression', async () => { | ||
const { enhance, prisma } = await loadSchema( | ||
` | ||
model User { | ||
id String @id @default(uuid()) | ||
todos Todo[] | ||
@@auth | ||
@@allow('all', true) | ||
} | ||
model Todo { | ||
id String @id @default(uuid()) | ||
user_id String | ||
user User @relation(fields: [user_id], references: [id]) | ||
images File[] @relation("todo_images") | ||
documents File[] @relation("todo_documents") | ||
@@allow('all', true) | ||
} | ||
model File { | ||
id String @id @default(uuid()) | ||
s3_key String @unique | ||
label String | ||
todo_image_id String? | ||
todo_image Todo? @relation("todo_images", fields: [todo_image_id], references: [id]) | ||
todo_document_id String? | ||
todo_document Todo? @relation("todo_documents", fields: [todo_document_id], references: [id]) | ||
@@allow('all', true) | ||
} | ||
`, | ||
{ logPrismaQuery: true } | ||
); | ||
|
||
const user = await prisma.user.create({ | ||
data: {}, | ||
}); | ||
await prisma.todo.create({ | ||
data: { | ||
user_id: user.id, | ||
|
||
images: { | ||
create: new Array(3).fill(null).map((_, i) => ({ | ||
s3_key: randomBytes(8).toString('hex'), | ||
label: `img-label-${i + 1}`, | ||
})), | ||
}, | ||
|
||
documents: { | ||
create: new Array(3).fill(null).map((_, i) => ({ | ||
s3_key: randomBytes(8).toString('hex'), | ||
label: `doc-label-${i + 1}`, | ||
})), | ||
}, | ||
}, | ||
}); | ||
|
||
const db = enhance(); | ||
|
||
const todo = await db.todo.findFirst({ where: {}, include: { documents: true } }); | ||
await expect( | ||
db.todo.update({ | ||
where: { id: todo.id }, | ||
data: { | ||
documents: { | ||
update: todo.documents.map((doc: any) => { | ||
return { | ||
where: { s3_key: doc.s3_key }, | ||
data: { label: 'updated' }, | ||
}; | ||
}), | ||
}, | ||
}, | ||
include: { documents: true }, | ||
}) | ||
).toResolveTruthy(); | ||
}); | ||
}); |