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

Error IN operator

Open Yanis540 opened this issue 1 year ago • 3 comments

Hi I'm expriencing some trouble with the IN operator,

user facing error: Unable to match input value to any allowed input type for the field. Parse errors: [Unable to match input value to any allowed input type for the field. Parse errors: [Invalid argument type. 
`connect` should be of any of the following types: `UserWhereUniqueInput`, Invalid argument type. `id` should be of any of the following types: `String`], Unable to match input value to any allowed input type for the field. Parse errors: [Invalid argument type. `connect` should be of any of the following types: `UserWhereUniqueInput`, Invalid argument type. `id` should be of any of the following types: `String`]]  

here's my schema :

model User {
    id        String    @id @default(cuid())
    ...
    chats     Chat[]
}
model Chat {
    id       String    @id @default(cuid())
    ....
    users    User[]
}

and doing this request :

       _, err := prisma.Chat.FindUnique(
		db.Chat.ID.Equals(chat.ID),
	).With(
		db.Chat.Users.Fetch(),
	).Update(
		db.Chat.Users.Link(
			db.User.ID.In([]string{"cltuva3xs0000tn3vhv5oc13p"}),
		),
	).Exec(ctx)

i checked many times that the chat exists, and that the user with the ID cltuva3xs0000tn3vhv5oc13p exists.

Any idea ?

Yanis540 avatar Apr 29 '24 22:04 Yanis540

You can't use .In when linking, it needs to be db.User.ID.Equals("cltuva3xs0000tn3vhv5oc13p"). You can define multiple .ID.Equals for many relations.

steebchen avatar Apr 29 '24 23:04 steebchen

Okey that's the basic solution, but since in real life we tend to have more data like a slice of string what could we do then ??? i personnaly think that the solution with the In is more elegant ?? and i think it's also implemented in prisma ( javascript version), even if i know the golang version is still on alpha it might seem logical to put that into perspective ? https://stackoverflow.com/questions/72566290/how-to-use-where-in-in-prisma

Yanis540 avatar Apr 29 '24 23:04 Yanis540

You can use it in a where query yes, but not when linking objects. This is the same behavior as Prisma JS I believe. You can put multiple options in the .Link for many relationships:

 db.Foo.Bars.Unlink(
    db.Bar.ID.Equals(id1),
    db.Bar.ID.Equals(id2),
    db.Bar.ID.In(ids),
 ),

steebchen avatar Apr 30 '24 10:04 steebchen