Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error IN operator #1264

Open
Yanis540 opened this issue Apr 29, 2024 · 3 comments
Open

Error IN operator #1264

Yanis540 opened this issue Apr 29, 2024 · 3 comments

Comments

@Yanis540
Copy link

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 ?

@steebchen
Copy link
Owner

steebchen commented Apr 29, 2024

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.

@Yanis540
Copy link
Author

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

@steebchen
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants