How to query all, that have spicific values in array field?


#1

For example i have users, that have rights, the rights is array of enum values, how can i query users with specific rights in array?

User {
id
name
rights: [Rights]
}
enum Rghts {
RIGHT1
RIGHT2
SECOND RIGHTS
etc…
}
How to get all users with rights field, that contain [RIGHT1] ?


#2

You can’t they do not support queries against scalar lists. You have to make your rights a first class object with an Id so it creates a relationship table.


#3

I can just suggest to use different types for Rights instead of using enums. In this way you can easily manage and filter Rights. It is also more flexible way when you want to add new rights to your system.