prisma-client-go icon indicating copy to clipboard operation
prisma-client-go copied to clipboard

Error in query graph construction when trying to attach m2m with .InIfPresent

Open hi019 opened this issue 2 years ago • 1 comments

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.

hi019 avatar Dec 03 '21 18:12 hi019

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),
)

steebchen avatar Dec 31 '21 11:12 steebchen