I'm having trouble finding the best way to filter on a has_many through relationship directly with Active Record. I've found a bunch of posts here that almost address the issue but none of the answers have worked for me.
Group:
has_many :taggings, as: :taggable
has_many :tags, :through => :taggings
User:
has_many :taggings, as: :taggable
has_many :tags, :through => :taggings
I want to find all users who have tags that match a single groups tags
This following method works but I would rather assemble the list with a query.
def interest_matches
matched_users = Array.new
self.tags.uniq.each do |tag|
tag.users.map{ |u| matched_users.push(u) unless matched_users.include?(u) }
end
matched_users
end
Any advice is much appreciated!