From e08779affa306d74385d142ddf375e1382777300 Mon Sep 17 00:00:00 2001 From: Felix Wolfsteller Date: Mon, 17 Oct 2016 22:41:12 +0200 Subject: [PATCH] unscope product search (#25) --- lib/rawbotz/models/search.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/rawbotz/models/search.rb b/lib/rawbotz/models/search.rb index d40a43a..edbde5b 100644 --- a/lib/rawbotz/models/search.rb +++ b/lib/rawbotz/models/search.rb @@ -9,17 +9,16 @@ class Search attr_accessor :term, :fields, :products def perform! - # Live could be so easy with AR5 #or + # Life could be so easy with AR5 #or constraints = [] if [*@fields].include?(:name) || [*@fields].include?(:all) - constraints << LocalProduct.name_ilike(@term).arel.constraints - puts constraints[0].inspect + constraints << LocalProduct.unscoped.name_ilike(@term).arel.constraints end if [*@fields].include?(:id) || [*@fields].include?(:all) - constraints << LocalProduct.where(id: @term.to_i).arel.constraints + constraints << LocalProduct.unscoped.where(id: @term.to_i).arel.constraints end if [*@fields].include?(:product_id) || [*@fields].include?(:all) - constraints << LocalProduct.where(product_id: @term.to_i).arel.constraints + constraints << LocalProduct.unscoped.where(product_id: @term.to_i).arel.constraints end arel = constraints[0] @@ -33,7 +32,7 @@ def perform! [LocalProduct.arel_table[:product_id].as("TEXT")] ) - @products = LocalProduct.where( + @products = LocalProduct.unscoped.where( id_code.matches("%#{@term}%" ).or(product_id_code.matches("%#{@term}%") ).or(