diff --git a/app/models/log.rb b/app/models/log.rb index 195f63ba7..00a178e2b 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -50,7 +50,13 @@ class Log < ApplicationRecord 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, -> { 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_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)) } diff --git a/yarn.lock b/yarn.lock index ff3fe1709..9798885e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2880,9 +2880,9 @@ ignore@^5.1.9: integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ== immutable@^4.0.0: - version "4.3.7" - resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.7.tgz#c70145fc90d89fb02021e65c84eb0226e4e5a381" - integrity sha512-1hqclzwYwjRDFLjcFxOM5AYkkG0rpFPpr1RLPMEuGczoS7YA8gLhy8SWXYRAA/XwfEHpfo3cw5JGioS32fnMRw== + version "4.3.8" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.8.tgz#02d183c7727fb2bb1d5d0380da0d779dce9296a7" + integrity sha512-d/Ld9aLbKpNwyl0KiM2CT1WYvkitQ1TSvmRtkcV8FKStiDoA7Slzgjmb/1G2yhKM1p0XeNOieaTbFZmU1d3Xuw== import-fresh@^3.2.1, import-fresh@^3.3.0: version "3.3.0"