scope:search_by_postcode,->(postcode){where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE REPLACE(locations.postcode, ' ', '') ILIKE ?)","%#{postcode.delete(' ')}%")}
scope:search_by_location_name,->(name){where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE locations.name ILIKE ?)","%#{name}%")}
scope:search_by,lambda{|param|
select("schemes.*, lower(service_name) as lowercase_service_name")
.search_by_postcode(param)
search_by_postcode(param)
.or(search_by_service_name(param))
.or(search_by_location_name(param))
.or(filter_by_id(param)).distinct
.or(filter_by_id(param))
}
scope:order_by_service_name,lambda{
select("schemes.*, lower(service_name) as lowercase_service_name")