给定一串电子邮件,例如:
emails = "atttt@bbb-inc.com, scott@sara.com, a@a.com, rasx@bo.com"
通过一个查询,我想返回所有匹配的用户记录,其中:
User.rb (id,email)
这是我的查询,但如果我将电子邮件设置为多个电子邮件,它不会返回结果:
User.where("email IN (?)", emails)
User Load (1.0ms) SELECT "users".* FROM "users" WHERE (users.deleted_at IS NULL) AND (email IN ('atttt@bbb-inc.com,, scott@sara.com, a@a.com, rasx@bo.com'))
=> []
关于如何更新此 User.where 查询以从提供的电子邮件中获取所有匹配用户的建议?谢谢。
最佳答案
首先,将 emails
变成一个数组:
emails = "atttt@bbb-inc.com, scott@sara.com, a@a.com, rasx@bo.com".split(', ')
然后你可以调用:
User.where(:email => emails)
关于sql - 如何使用 IN 查询匹配的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12631341/