|
|
|
@ -6,8 +6,8 @@ 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("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{UKPostcode.parse(postcode)}%") } |
|
|
|
|
scope :search_by_location_name, ->(name) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.name ILIKE ?", "%#{name}%") } |
|
|
|
|
scope :search_by_postcode, ->(postcode) { left_joins(:locations).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|
|
scope :search_by_location_name, ->(name) { left_joins(:locations).where("locations.name ILIKE ?", "%#{name}%") } |
|
|
|
|
scope :search_by, lambda { |param| |
|
|
|
|
search_by_postcode(param) |
|
|
|
|
.or(search_by_service_name(param)) |
|
|
|
|