Search by bitmask in ActiveRecord

I have a user table with a bitmask field that has a permission mask in it. Locally, I can determine if a user has a specific permission by doing a bitmask (UserPermissions&Perm)==Perm. However, I want to be able to release find_by_maskor something similar, perhaps using :conditions, but I cannot understand how I can query the database to get a list of users with the appropriate permission mask.

Any ideas using ActiveRecord?

In particular, this should work using sqlite and postgres

+5
source share
1 answer

, , , . - .

, SQL- , :

User.where('permissions & ? > 0', Perm)
+12

All Articles