Module: CaseSensitivity::ClassMethods

Defined in:
app/models/concerns/case_sensitivity.rb

Instance Method Summary collapse

Instance Method Details

#iwhere(params) ⇒ Object

Queries the given columns regardless of the casing used.

Unlike other ActiveRecord methods this method only operates on a Hash.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/concerns/case_sensitivity.rb', line 9

def iwhere(params)
  criteria   = self
  cast_lower = Gitlab::Database.postgresql?

  params.each do |key, value|
    column = ActiveRecord::Base.connection.quote_table_name(key)

    if cast_lower
      condition = "LOWER(#{column}) = LOWER(:value)"
    else
      condition = "#{column} = :value"
    end

    criteria = criteria.where(condition, value: value)
  end

  criteria
end