0

I am new to Datamapper. Is there any way to write case insensitive query in datamapper because I am searching for presence of a name in a table with datamapper. Normally we write query in datamapper like this say,

Student.all(:name => "XYZ") where name can be of the form xyz, Xyz and XYZ.

So in the above query what additional operator I have to add to make the above query case insensitive.

Joy
  • 4,197
  • 14
  • 61
  • 131
  • Check out this similar answer: http://stackoverflow.com/questions/7659045/case-insensitive-like-ilike-in-datamapper-with-postgresql – Kieran Andrews Jan 23 '14 at 06:45

3 Answers3

1

For datamapper you have to use

Student.all(:conditions => [ "lower(name) = ?", name.downcase ])
0

Modify your query:

name = "XyZ"
Student.find(:all, :conditions => [ "lower(name) = ?", name.downcase ])
Ganesh Kunwar
  • 2,643
  • 2
  • 20
  • 36
-2

You can try this

name = "XyZ"
Student.where("lower(name) = ?", name.downcase)

or you can put validation in modal also like this

validates_uniqueness_of :name, :case_sensitive => false
Jeet
  • 1,350
  • 1
  • 15
  • 32