Activerecord :condition syntax of an empty field?
What is the rails activerecord
syntax for select records with an empty field? For example, I want to find all the records that the middle_name
field is empty (length of the string < 1) for a user
dat开发者_如何学Cabase. Thanks!
In Rails 2
User.find(:all, :conditions=>["middle_name is ? or middle_name = ?", nil, ''])
In Rails 3, you can also do it in following way
User.where("middle_name is NULL or middle_name = ''")
精彩评论