Bug description
Foreign key value is not being set when using a nested create for a one-to-one relation.
How to reproduce
- Create the following schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Company {
id String @default(cuid()) @id
payments Payment[]
}
model Visit {
id String @default(cuid()) @id
payment Payment?
}
model Payment {
id String @default(cuid()) @id
company Company @relation(fields: [companyId], references: [id])
companyId String
visit Visit? @relation(fields: [visitId], references: [id])
visitId String?
}
-
Create a company (need the id for the next step)
-
Run the following script
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
const main = async () => {
const newVisit = await prisma.visit.create({ data: {} })
await prisma.visit.update({
data: {
payment: {
create: {
company: { connect: { id: '{{ company id here }}' }}
}
}
},
where: { id: newVisit.id }
})
}
main()
.then(() => console.log('Done 🎉'))
.catch(err => console.log(err))
.finally(() => prisma.disconnect())
- Check the database -
payment.companyId will be set, however payment.visitId is still NULL, despite the payment being created within a visit update. There's no way to connect that payment to visit, since the nested create does not allow a direct visit connection (since it's part of a visit update).
Without the company connection it works, so it's perhaps something to do with connecting to multiple parents?
Expected behavior
Payments created within an update visit mutation should be connected to the visit.
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Prisma version: 2.2.2
- Node.js version: 14.5.0
Bug description
Foreign key value is not being set when using a nested create for a one-to-one relation.
How to reproduce
Create a company (need the id for the next step)
Run the following script
payment.companyIdwill be set, howeverpayment.visitIdis stillNULL, despite the payment being created within a visit update. There's no way to connect that payment to visit, since the nested create does not allow a direct visit connection (since it's part of a visit update).Without the company connection it works, so it's perhaps something to do with connecting to multiple parents?
Expected behavior
Payments created within an update visit mutation should be connected to the visit.
Environment & setup