Cannot update a column value to null?
See original GitHub issueI have a foreign key column in my table, call it parentId, when parentId is null, i know that the current row has no parent. If it is not null then I can use that foreign key to connect with the corresponding parent. When trying to use update in prisma, i run into a few issues:
First, I cannot directly update the value of parentId or any foreign key for that matter, and instead an error is thrown and I am basically told that parentId field doesnt exist and instead what im looking for is the relation field parent. So the below does not work
db.folder.update({
data: {
parentId: obj.id
},
where: { id },
})
So when i try to instead update the relation field parent like this:
db.folder.update({
data: {
parent:
{
connect: {
id: obj.id,
},
},
},
where: { id },
})
Then if obj.id is null, an error is thrown because you cant connect with a null id, so instead i add a conditional,
db.folder.update({
data: {
parent:
obj.id == null
? null
: {
connect: {
id: obj.id,
},
},
},
where: { id },
})
And this does not work either, instead every time i pass in null, the value in the db is not changed, which i guess is a safeguard so that if no parameter is passed in, it doesnt nullify the value. However, I need to update the value of parentId to be null in certain cases… How can i do that??
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Related StackOverflow Question
if anybody is still looking for answer:
Thanks @dpetrick, I missed that detail.
@ShehabSN You can use the following client attain the required result: