Combining Enums with Other Query Conditions

Enums can be used in complex queries with additional conditions.

User.where(status: :active).where("created_at > ?", 7.days.ago)

This fetches all active users created in the last 7 days.

Querying Multiple Conditions with OR

User.where("status = ? OR status = ?", User.statuses[:inactive], User.statuses[:banned])

Equivalent to:

User.where(status: [:inactive, :banned])

Fetching the First or Last Record Matching an Enum

User.where(status: :banned).first
User.where(status: :banned).last