Forum: Ruby on Rails Active record queries, reverse lookup on has_many: :through =>

Posted by Niklas Nson (Guest)
on 2012-11-27 07:34
(Received via mailing list)
*User.rb*
has_many :looking_for_whos, :class_name => "UserLookingForWho"
has_many :asset_looking_for_whos, :through => :looking_for_whos
belongs_to :asset_usertype

In a controller i can do the following:

*@users = User.where(asset_usertype_id: 
[current_user.looking_for_who_ids])*
to get all users who's *asset_user_type_id* is in *looking_for_who_ids*,
but the trick i would like to add a reverse lookup as well; to maker 
sure
that Users selected *also* is
looking for the current_user.asset_usertype_id. But i cant get my head
around what to do, someone
who could give me some pointers ?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.