Permalink
Browse files

Fix mysql case sensitive tag generation and searching

  • Loading branch information...
1 parent c27038e commit 5022671a77836db2923aaa0bb441b9d8bd44247e @bnorton bnorton committed Oct 9, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/acts_as_taggable_on/tag.rb
@@ -18,15 +18,15 @@ class Tag < ::ActiveRecord::Base
def self.named(name)
if ActsAsTaggableOn.strict_case_match
- where(["name = ?", name])
+ where(["name = #{binary}?", name])
else
where(["lower(name) = ?", name.downcase])
end
end
def self.named_any(list)
if ActsAsTaggableOn.strict_case_match
- where(list.map { |tag| sanitize_sql(["name = ?", tag.to_s.mb_chars]) }.join(" OR "))
+ where(list.map { |tag| sanitize_sql(["name = #{binary}?", tag.to_s.mb_chars]) }.join(" OR "))
else
where(list.map { |tag| sanitize_sql(["lower(name) = ?", tag.to_s.mb_chars.downcase]) }.join(" OR "))
end
@@ -81,9 +81,14 @@ def count
class << self
private
+
def comparable_name(str)
str.mb_chars.downcase.to_s
end
+
+ def binary
+ /mysql/ === ActiveRecord::Base.connection_config[:adapter] ? "BINARY " : nil
+ end
end
end
end

0 comments on commit 5022671

Please sign in to comment.