prisma-client-go
prisma-client-go copied to clipboard
Error in query graph construction when trying to attach m2m with .InIfPresent
Hey. I have a Category and Post linked together with a many to many relationship. A post can have many categories and a category can have many Posts. I'm trying to Link a category to a Post, like this:
// Link the category to the post
_, err = client.Post.FindUnique(db.Post.ID.Equals(post.ID)).
Update(db.Post.Categories.Link(
db.Category.ID.InIfPresent([]int{category.ID}),
),
).
Exec(ctx)
But I'm getting this error. I've made a small reproduction at https://github.com/hi019/prisma-go-issue. Using db.Category.ID.Equals(category.ID)
instead of the InIfPresent works, but I would like to pass a slice of ids if possible.
I think you would need to pass additional parameters in .Link, the operation In just does not work in this case (it is actually a bug that this syntax does not fail at compile time).
i.e.
.Link(
..Equals(category.ID),
..Equals(something),
)