Browse Source

CLDC-4055: Use name property for filtering organisations (#3097)

main v0.5.20
Samuel Young 4 days ago committed by GitHub
parent
commit
4af4c948e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      app/models/organisation.rb

8
app/models/organisation.rb

@ -38,7 +38,13 @@ class Organisation < ApplicationRecord
Organisation.where(id: ids) Organisation.where(id: ids)
end end
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by_name, lambda { |name|
# we can't use the activerecord queries to query the DB as the `name` col doesn't update when the org changes name.
# this is due to the info being stored in the organisation_name_changes table.
# so we load all and filter in memory. the number of organisations is small so this should be fine.
matched_ids = all.filter { |org| org.name.downcase.include?(name.downcase) }.map(&:id)
where(id: matched_ids)
}
scope :search_by, ->(param) { search_by_name(param) } scope :search_by, ->(param) { search_by_name(param) }
scope :filter_by_active, -> { where(active: true) } scope :filter_by_active, -> { where(active: true) }
scope :filter_by_inactive, -> { where(active: false) } scope :filter_by_inactive, -> { where(active: false) }

Loading…
Cancel
Save