In my rails app, I use MongoDB. I have 4 models including the admin. All the entities have an email address. I need to make validation to make sure that the email is unique for all the models.
Is there a simpler/better way to do that other than searching for the email in every model?
like
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