【发布时间】:2013-09-12 17:26:16
【问题描述】:
我正在尝试通过用户名或电子邮件帮助查找用户记录。唯一的问题是用户名存储在关联的UserDetail 模型中。
class User
has_one :user_detail
def self.find_by_username_or_email(value)
# This is effectively pseudocode for the query I'd like to write.
query = "lower(email) = :value OR user_detail.username = :value"
where([query, { value: value }]).first
end
end
如何编写与关联user_detail 记录上的电子邮件或用户名匹配的查询?
【问题讨论】:
-
冷静下来 Yoshiji :-) 我早上回来工作时会好好看看。如果对您有帮助,您将获得奖励!
标签: mysql sql ruby-on-rails activerecord ruby-on-rails-3.2