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
Post a Comment