debian-mirror-gitlab/app/models/concerns/case_sensitivity.rb

30 lines
753 B
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
# Concern for querying columns with specific case sensitivity handling.
module CaseSensitivity
extend ActiveSupport::Concern
module ClassMethods
# Queries the given columns regardless of the casing used.
#
# Unlike other ActiveRecord methods this method only operates on a Hash.
def iwhere(params)
criteria = self
cast_lower = Gitlab::Database.postgresql?
params.each do |key, value|
column = ActiveRecord::Base.connection.quote_table_name(key)
2017-08-17 22:00:37 +05:30
condition =
if cast_lower
"LOWER(#{column}) = LOWER(:value)"
else
"#{column} = :value"
end
2015-10-24 18:46:33 +05:30
criteria = criteria.where(condition, value: value)
end
criteria
end
end
end