Remove redundant code

bill_address is already joined in this query.
The class variable isn't needed outside this scope.

Arguably I think the condition on the select isn't needed; it wouldn't hurt to always select spree_addresses. But I'll try to avoid changing too much..
This commit is contained in:
David Cook
2023-08-24 10:12:13 +10:00
committed by Maikel Linke
parent 04312b05c6
commit ccafdc4494

View File

@@ -15,21 +15,19 @@ class SearchOrders
attr_reader :params, :current_user
def fetch_orders
@search = search_query.
search = search_query.
includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle).
ransack(params[:q])
@search = @search.result(distinct: true)
ransack(params[:q]).
result(distinct: true)
if ['bill_address',
'billing_address'].any?{ |param|
params.dig(:q, :s)&.starts_with?(param)
}
@search = @search.left_joins(:bill_address).
select('spree_addresses.*, spree_orders.*')
search = search.select('spree_addresses.*, spree_orders.*')
end
@search
search
end
def search_query