Is there a way to disconnect relations using `pris...
# orm-help
m
Is there a way to disconnect relations using
prisma.upsert
? For example:
EventOptions: { connect: [{ eventOptionId: 'some_id' }] }
it connects the
EventOptions
field to
some_id
, but leaves
EventOptions
other relations intact. Is there a way to replace the connections with only the
some_id
connection?
r
@martin I think using
set
should do it.
m
Can you please provide a link to the documentation on
set
Ryan? Can’t find any.
r
You can replace
connect
with
set
in the above example and that will work 🙂
m
Oh, awesome! Thank you!
For which Prisma version, @Ryan? Getting error for
2.11.0
.
r
It should work. For e.g this being my schema:
Copy code
model User {
  id        Int      @id @default(autoincrement())
  name      String?
  posts     Post[]
  createdAt DateTime @default(now())
}

model Post {
  id     Int   @id @default(autoincrement())
  user   User? @relation(fields: [userId], references: [id])
  userId Int?
}
I can use
set
like this:
Copy code
await prisma.user.upsert({
    where: { id: 1 },
    create: { name: 'name' },
    update: { name: 'name', posts: { set: [{ id: 'something' }] } },
  })
m
Got it, that worked, thanks Ryan!
Key was to not use
set
inside the
create
portion.
💯 1