I have a table of post and a table of users. I want to assign a list of posts to a new user. I have tried prisma updateMany but it does not seem to work with foreign keys. How should I go on with this?
I have a table of post and a table of users. I want to assign a list of posts to a new user. I have tried prisma updateMany but it does not seem to work with foreign keys. How should I go on with this?
Without seeing the model it's difficult to say, but traditionally it would look like this with prisma:
await this.prisma.posts.updateMany({
where: {
<conditions>
},
data: {
user: {
connect: {
id: user.id;
}
}
});
In my experience, it's been better to use the "connect" on the user, vs simply updating the userId field to keep FKs in check.