Scopes
class User
include Clear::Model
primary_key
column role : String
column role_level : Int32
column email : String
column active : Bool
scope :with_privileges do |level|
where{ role.in?(%w(superadmin admin)) | (role_level > level) }
end
scope(:active){ where(active: true) }
end
# Later one:
User.with_privileges(3).each do |x|
puts "Admin #{x.id} - #{x.email}"
endLast updated