I use enum
for a column in my users
table. I want to be able to find all users who are not pending. This is my current code:
enum approval_status: [:pending, :approved, :declined]
User.where.not(approval_status: :pending)
But the SQL query becomes this:
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE (`users`.`approval_status` != NULL)
No matter what enum value I put in, the SQL turns it to NULL
How do I get ALL users, EXCEPT for a particular value of the approval_status column?
In Rails 6, negative scopes are added on the enum values.
You can use it like this:
User.not_pending
User.not_approved
User.not_declined
Related pull request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With