I have a table, "posts" like so:
+----+---------+------------+
| id | author | text |
+----+---------+------------+
| 1 | bob | hello |
| 2 | jim | hi bob |
+----+---------+------------+
and also "tags" like so:
+----+--------------+
| id | name |
+----+--------------+
| 1 | bugs |
| 2 | project_foo |
| 3 | project_bar |
+----+--------------+
and lastly "post_tags" like:
+------+------+
| post | tag |
+------+------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 3 |
+------+------+
Posts are tagged with any number of tags. With the above data, what is the best way for me to query "give me the posts that have ALL tags in the list (1,2)"? These would be the posts tagged as "bugs, project_foo"
A joined search with "IN" doesn't work for me as it is returning posts that match any of the listed tags, so I will receive "project_bar" bug posts as well even though they aren't even tagged as "project_foo". It would be completely fine to return posts that contain tags not in the specified list, given that the post at least has the tags mentioned. So "bugs, project_foo, project_bar" would be fine, but "bugs, project_bar" would not.
I would prefer to do this with normal ResultSet usage, but am comfortable doing in a custom ResultSource::View. Problem is, I can't figure out how to do this in raw sql either.
Is there a practical way to do what I am attempting, or is my table setup just wrong for what I am trying to achieve?
Thank you.