Created
March 28, 2023 07:45
-
-
Save mskog/3f7a933d175c296cc0dc6459a9aa3e3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def items_with_joins | |
@items_with_joins ||= items.joins("LEFT JOIN services ON services.id = communication_operator_diff_file_items.service_id") | |
.joins("LEFT JOIN offers_products ON offers_products.id = services.offers_product_id") | |
.joins("LEFT JOIN broadband_products ON broadband_products.id = offers_products.product_id") | |
.preload(service: { offers_product: :product, customer: nil }) | |
.where([search_clause, {query: "%#{@params[:search]}%"}]) | |
end | |
def items_scope | |
items_with_joins.order(order_params) | |
.where(error: error, measure_status: measure_status, status: status) | |
end | |
def search_clause | |
<<~SQL | |
bandwidth ILIKE :query | |
OR street_address ILIKE :query | |
OR city ILIKE :query | |
OR apartment_number ILIKE :query | |
OR communication_operator_diff_file_items.access_id ILIKE :query | |
OR services.details -> 'provider_service_id' ILIKE :query | |
OR services.details -> 'provider_customer_id' ILIKE :query | |
OR services.name ILIKE :query | |
OR note ILIKE :query | |
OR info_1 ILIKE :query | |
OR info_2 ILIKE :query | |
OR COALESCE(array_to_string(ids, ','), '') ILIKE :query | |
SQL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment