How to select the items that have an association with any user in Rails -


i have relation between user , hobby, relation in user has_and_belongs_to_many , 1 hobby has_and_belongs_to_many.

i'm trying list of hobbies users have chosen. example if 1 user selected soccer , selected basketball, want have query shows me "soccer, basketball". how can join in query? right i'm grabbing hobbies each user via user.find(id).hobbies

you inner join hobbies users hobbies chosen users.

hobby.joins(:users).uniq 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -