Skip to content

Commit

Permalink
unscope product search (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwolfst committed Oct 17, 2016
1 parent eefca2f commit e08779a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/rawbotz/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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(
Expand Down

0 comments on commit e08779a

Please sign in to comment.