在我的 rails 应用程序中,我使用 MongoDB。我有 4 个模型,包括管理员。所有实体都有一个电子邮件地址。我需要进行验证以确保电子邮件对于所有模型都是唯一的。
除了在每个模型中搜索电子邮件之外,还有更简单/更好的方法吗?
喜欢
def email_uniquness_across_models(email)
User.where(email: email).exists? ||
Admin.where(email: email).exists? ||
Transporter.where(email: email).exists? ||
Company.where(email: email).exists?
end
Run Code Online (Sandbox Code Playgroud)