Error IN operator
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 ?
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.
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
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),
),