User has_and_belongs_to_many tags
Tag has_and_belongs_to_many users
I'm looking for a way to get every user that has tags 2
and 5
with one query, preferably built using activerecord.
I know I could do this
users1 = Tag.find(2).users
users2 = Tag.find(5).users
usersFinal = users1 & users2
But I want to get the list of users and merge them with SQL to prevent merging arrays in ruby.
EDIT: I'm using mysql2
You should use the map method:
Edit2
You can also use includes: