I have two tables, “users” and “users_emails”.
users have the following columns: |id|name|
users_emails have the following columns: |user_id|email|
The classes look like the following:
class UsersEmail< ActiveRecord::Base
class User< ActiveRecord::Base
What I’m trying to do is find all the users whom have a particular
I can do it has the following:
- get all user_id’s from user_emails table who has email = :email (user
- then for those user_ids get the user ojects from the users table by
I can get the email’s based on user name by the following:
User.find(1).user_emails but this is not what I want. I want
Users whom have a particular email address.
I’m wondering what is the nice way of doing this (the rails way using
methods on ActiveRecord). Or perhaps my assoications and tables are not
correct to facilitate such a query. The following does not work:
emails = UsersEmail.find(:condition =>…)
Any help would be greatly appreciated.