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

how can i exclude a field while finding model. #920

Closed
egely1337 opened this issue Jul 14, 2023 · 9 comments · Fixed by #1250
Closed

how can i exclude a field while finding model. #920

egely1337 opened this issue Jul 14, 2023 · 9 comments · Fixed by #1250

Comments

@egely1337
Copy link

how can i do this? i can do this in javascript using select field. how can i do this in go client???

@steebchen
Copy link
Owner

It's not possible yet in the Go client. Can you please describe why you want this feature? Is there a big field which you want to exclude for performance?

also see #346 for selecting fields

@egely1337
Copy link
Author

egely1337 commented Jul 15, 2023

i dont want to user see hashedpassword

@steebchen
Copy link
Owner

Good point! I'll put this into the 'soon' list, it would be indeed cool if specific fields could be ignored. However, note that specifically excluding fields might a bit dangerous as the default is returning all, so you might be better off to just selecting the fields you want. This is also not supported yet, but you can work around this by defining a new struct which just returns the fields you want:

user, err := db.User.FindUnique(...).Exec(ctx)

u := struct{
  Name string `json:"string"`
}{
  Name: user.Name,
}

// do something with u
return u

or

user, err := db.User.FindUnique(...).Exec(ctx)

newUser := db.UserModel{
  ID: user.ID,
  Name: user.Name,
}

return newUser

@egely1337
Copy link
Author

thank you for suggestion

@Chalwe19

This comment was marked as off-topic.

@steebchen

This comment was marked as off-topic.

@pikanezi
Copy link

pikanezi commented Nov 8, 2023

@steebchen any news on this feature? even with your suggestions, its a pain when you have to use FindMany as it adds a lot of unnecessary operations

@steebchen
Copy link
Owner

@pikanezi

Not sure what you mean by "have to use FindMany". Using structs is indeed not ideal

I'm currently working on a few Go client things, feel free to sponsor me (or ask your employer) to potentially speed things up ;)

@steebchen
Copy link
Owner

Regarding the implementation, it would most likely implementing select instead of implementing an exclude function (similar to what the JS client does).

@steebchen steebchen linked a pull request Apr 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

4 participants