Exclusive filtering by tag
Posted
by KaptajnKold
on Stack Overflow
See other posts from Stack Overflow
or by KaptajnKold
Published on 2010-04-21T09:39:26Z
Indexed on
2010/04/21
10:03 UTC
Read the original article
Hit count: 247
I'm using rails 3.0 and MySql 5.1
I have these three models:
Question, Tag and QuestionTag.
Tag has a column called name.
Question has many Tags through QuestionTags and vice versa.
Suppose I have n tag names. How do I find only the questions that have all n tags, identified by tag name.
And how do I do it in a single query.
(If you can convince me that doing it in more than one query is optimal, I'll be open to that)
A pure rails 3 solution would be preferred, but I am not adverse to a pure SQL solution either.
© Stack Overflow or respective owner