Browse Source

CLDC-4226: Unionise org filter scope (#3209)

* CLDC-4226: unionise org filter scope

* CLDC-4226: add todo comment

* CLDC-4226: respond to comments

* CLDC-4226: disambiguate scope again

* CLDC-4226: use unscoped in block form
CLDC-4167-address-line-search-bug v0.6.4
Nat Dean-Lewis 2 weeks ago committed by GitHub
parent
commit
27cad52e1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      app/models/log.rb

8
app/models/log.rb

@ -50,7 +50,13 @@ class Log < ApplicationRecord
scope :has_old_form_id, -> { where.not(old_form_id: nil) } scope :has_old_form_id, -> { where.not(old_form_id: nil) }
scope :imported_2023_with_old_form_id, -> { imported.filter_by_year(2023).has_old_form_id } scope :imported_2023_with_old_form_id, -> { imported.filter_by_year(2023).has_old_form_id }
scope :imported_2023, -> { imported.filter_by_year(2023) } scope :imported_2023, -> { imported.filter_by_year(2023) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } # TODO: CLDC-4273: use .union in filter_by_organisation rather than raw SQL
scope :filter_by_organisation, lambda { |orgs, _user = nil|
owned = unscoped { where(owning_organisation: orgs).select(:id) }
managed = unscoped { where(managing_organisation: orgs).select(:id) }
where("#{table_name}.id = ANY(ARRAY(#{owned.to_sql} UNION #{managed.to_sql}))")
}
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) } scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) }
scope :filter_by_managing_organisation, ->(managing_organisation, _user = nil) { where(managing_organisation:) } scope :filter_by_managing_organisation, ->(managing_organisation, _user = nil) { where(managing_organisation:) }
scope :filter_by_user_text_search, ->(param, user) { where(assigned_to: User.visible(user).search_by(param)) } scope :filter_by_user_text_search, ->(param, user) { where(assigned_to: User.visible(user).search_by(param)) }

Loading…
Cancel
Save