hello, when I delete a record that has an optional...
# orm-help
d
hello, when I delete a record that has an optional relation to another model, the optional relation's records also get deleted, any way to prevent this?
Copy code
model User {
    ....
    memos Memo[]
}

model Memo {
    userId String?
    user User? @relation(fields: [userId], references: [id])
}
it worked as expected (making the
FK
null in the optional relation model) after I dropped the database and did a
push
. is this supposed to be like this? it wont work without dropping the database?
j
Are you using the new
referentialActions
preview feature in 2.26.0?
r
@Dev__ 👋 We just released this feature today where you can set what happens
onDelete
. You can have a look at this here: https://github.com/prisma/prisma/releases/tag/2.26.0
d
I am on 2.22.0
nice, exactly what I needed 😄
was waiting for that feature
@Ryan does that mean I do not need to set the relations to optional anymore?
👍 1
r
For optional relations it’s
ON DELETE SET NULL
by default.
d
yes I understand, but before we were required to make the relation optional (even tho it wasnt), with this I could now use the onDelete SetNulll i assume?
r
But you cannot set a required relation
NULL
so that wouldn’t be possible.
d
alright, thanks. So I updated prisma to 2.26.0 and when I want to use the preview feature I get this
r
Does it work though when you run
prisma generate
? It’s possible that the extension isn’t the latest.
d
already did a generate and removed node_modules
j
Did you also update the VScode extension?
Does
npx prisma validate
also complain?
d
ah yes, the extension wasnt reloaded, works now
👍 2
j
Instant feature request for our VSCode extension 😄 https://github.com/prisma/language-tools/issues/815
👍 1