Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Postgresql uses ILIKE operator to case insensitive pattern matching

  • Loading branch information...
commit 16a2bf3a31b8db3ed70bf99f7f1d7f45f93a2d13 1 parent 2967a55
Kamil Giszczak authored tomeric committed
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/acts_as_taggable_on/tag.rb
View
15 lib/acts_as_taggable_on/tag.rb
@@ -16,19 +16,19 @@ class Tag < ::ActiveRecord::Base
### SCOPES:
def self.named(name)
- where(["name LIKE ?", name])
+ where(["name #{like_operator} ?", name])
end
def self.named_any(list)
- where(list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR "))
+ where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", tag.to_s]) }.join(" OR "))
end
def self.named_like(name)
- where(["name LIKE ?", "%#{name}%"])
+ where(["name #{like_operator} ?", "%#{name}%"])
end
def self.named_like_any(list)
- where(list.map { |tag| sanitize_sql(["name LIKE ?", "%#{tag.to_s}%"]) }.join(" OR "))
+ where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", "%#{tag.to_s}%"]) }.join(" OR "))
end
### CLASS METHODS:
@@ -63,5 +63,12 @@ def count
read_attribute(:count).to_i
end
+ class << self
+ private
+ def like_operator
+ connection.adapter_name == 'PostgreSQL' ? 'ILIKE' : 'LIKE'
+ end
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.