I have a Model called Department.
class Department < ActiveRecord::Base
# Associations
belongs_to :client
belongs_to :facility
scope :facility_departments, ->(facility_id) {
where("facility_id = ? ", facility_id)}
scope :matching_departments, ->(facility_id, identifier) {facility_departments(facility_id).where("
? REGEXP reg_exp ", identifier.to_s).order("weight DESC") }
end
- In the departments table I have a
facility_id, and a regular expression column. - I also have employees in my application, each one having a department id. In order to identify an employees department, I'm using scope
matching_departmentsin department model (see above). - Each employee has got an identifier too.
- All employees having a numeric identifier and identifier length = 9 , except 9 zeros (000000000) - should map to department 1.
So what should be the regular expression for department-1 in my departments table?
I updated it with (^[0-9]{9,}$) - matching all numeric identifiers with length 9. How can I exclude 9 zeros?