P粉9167604292023-08-27 15:43:23
I'm doing something very similar in my code:
const publication = await prisma.publication.create({ data: { title: e.title, type: e.type, content: e.content, user: { connect: { id: user.id } }, publicationStatus: { create: { status: 'DRAFT' } } } });
All of our publications
have a corresponding publicationStatus
, similar to the question you listed, maybe you can do this:
await prisma.user.create({ data: { settings: { create: { settingOne: true } } } })
or similar operation?
P粉7104549102023-08-27 12:46:38
This is impossible, because if both sides of the relationship are required, how can you create either one? So relational aspects without relational scalars (fields that represent foreign keys in the database) must be optional. You can decide which one yourself.
For example, you want to create User
, but Settings
is required, so you need to create Settings
first. But to create Settings
you also need User
because it is required in the Settings
model.
For more information please refer to the documentation