Planetscale pushing to an Array with Prisma?

So apparently you can't push items to array in mySQL? docs
const userId = ctx.userId
const status = await ctx.prisma.post.update({
where: {
id: input.postId,
},
data: {
likedBy: {
push: userId
},
},
const userId = ctx.userId
const status = await ctx.prisma.post.update({
where: {
id: input.postId,
},
data: {
likedBy: {
push: userId
},
},
This does not work. Any ideas?
Solution:
Glad you figured that out, For anyone stumbling across this, here is the relevant Prisma docs: https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-an-existing-record Feel free to mark one of these as the solution 😄...
Prisma
Relation queries (Concepts)
Prisma Client provides convenient queries for working with relations, such as a fluent API, nested writes (transactions), nested reads and relation filters.
Jump to solution
2 Replies
Luc Ledo
Luc Ledo•2y ago
I figured it out
const userId = ctx.userId
const status = await ctx.prisma.post.update({
where: {
id: input.postId,
},
data: {
likedBy: {
connect: { id: userId },
},
},
})
const userId = ctx.userId
const status = await ctx.prisma.post.update({
where: {
id: input.postId,
},
data: {
likedBy: {
connect: { id: userId },
},
},
})
It was very hard to find, prisma docs could be better
Solution
SinV
SinV•2y ago
Glad you figured that out, For anyone stumbling across this, here is the relevant Prisma docs: https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-an-existing-record Feel free to mark one of these as the solution 😄
Prisma
Relation queries (Concepts)
Prisma Client provides convenient queries for working with relations, such as a fluent API, nested writes (transactions), nested reads and relation filters.
Want results from more Discord servers?
Add your server