开发者

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 = ''")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜