简体   繁体   中英

Rails Model find Where Not | Query where not

I have a user model with optional twitter integration.

I've added a 'username' attribute that is only filled when a user has completed twitter authentication.

I want to find all users with the integration. What is the best way to find all objects where an attribute is something, or where it is not nil?

Rails4 / Rails 5 :

User.where.not(username: nil)

Rails 3:

User.where("username <> nil")

I would love to see other responses

你也可以在where语句中写sql:

User.where("username <> nil")

你可以执行简单的地方,如下所示不查询

Modal.where.not(name: "abc")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM