|
|
@ -4,6 +4,10 @@ class Scheme < ApplicationRecord |
|
|
|
has_many :locations |
|
|
|
has_many :locations |
|
|
|
has_many :case_logs |
|
|
|
has_many :case_logs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validates_presence_of :service_name |
|
|
|
|
|
|
|
validates_presence_of :scheme_type |
|
|
|
|
|
|
|
validates_presence_of :registered_under_care_act |
|
|
|
|
|
|
|
|
|
|
|
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } |
|
|
|
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } |
|
|
|
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } |
|
|
|
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } |
|
|
|
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|