0

ive got the following habtm relationship.

My model tag is associated with many taggroups. So i can have multiple taggroups which include the same tag. I have taggroup user views, which show all including tags of this taggroup. Now there is a special option ive got for taggroups, which is named "blacklisted". If a taggroup is marked as blacklisted, there is no user view for this taggroup AND all tags of this taggroup should not be visible in any other taggroup view where they are maybe also included. I hope is was clear enough and you will see my problem.

My question is now: how would a corresponding mysql query look like? I thought about an intersection of two joined tables, but as far as i know mysql isnt supporting intersections..

Thanks in advance.

pyran1208
  • 115
  • 2
  • 11

1 Answers1

0
SELECT DISTINCT Tag.* FROM taggroups TagGroup
INNER JOIN tag_taggroups TagTagGroup ON TagGroup.id = TagTagGroup.taggroup_id
INNER JOIN ( SELECT t.*  FROM 
tags t
INNER JOIN 
tag_taggroups ttg ON t.id = ttg.tag_id 
INNER JOIN taggroups tg ON tg.id = ttg.taggroup_id         
GROUP by t.id HAVING max(tg.blacklisted) = 0) AS Tag ON Tag.id = TagTagGroup.tag_id

solved with a friends help :)

pyran1208
  • 115
  • 2
  • 11