From fe77e9cc095b1fb41040270ef697391cb8a5daef Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 10 Sep 2013 11:05:29 +1000 Subject: [PATCH] Remove Spree::LIKE definition, as it is only used one place in all the code --- core/app/models/spree/product.rb | 4 +++- core/config/initializers/spree.rb | 5 ----- 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 core/config/initializers/spree.rb diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 24706cb2f78..4591aedc005 100755 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -146,7 +146,9 @@ def categorise_variants_from_option(opt_type) end def self.like_any(fields, values) - where_str = fields.map { |field| Array.new(values.size, "#{self.quoted_table_name}.#{field} #{LIKE} ?").join(' OR ') }.join(' OR ') + # PostgreSQL is case sensitive, so we need to use ILIKE to work around that. + like = ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' ? 'ILIKE' : 'LIKE' + where_str = fields.map { |field| Array.new(values.size, "#{self.quoted_table_name}.#{field} #{like} ?").join(' OR ') }.join(' OR ') self.where([where_str, values.map { |value| "%#{value}%" } * fields.size].flatten) end diff --git a/core/config/initializers/spree.rb b/core/config/initializers/spree.rb deleted file mode 100644 index 7bb41b84f1d..00000000000 --- a/core/config/initializers/spree.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Spree - if ActiveRecord::Base.connected? - LIKE = ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' ? 'ILIKE' : 'LIKE' - end -end