|
|
|
@ -6,7 +6,7 @@ class Scheme < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
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_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|
|
scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|
|
scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct } |
|
|
|
|
|
|
|
|
|
validate :validate_confirmed |
|
|
|
|