开发者

Activerecord :condition syntax of an empty field?

开发者 https://www.devze.com 2023-01-05 00:53 出处:网络
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 d

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

精彩评论

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