In my database I have 5 tables:
game(game_id,name,…)
tag (tag_id,name,…)
collection (coll_id,name,…)
collections_tags (id,coll_id,tag_id)
game_tag (id,game_id,tag_id)
Here are the relations in Collection model:
'collections_tags'=>array(self::HAS_MANY,'CollectionsTags', 'coll_id'),
'tags'=>array(self::HAS_MANY, 'Tag', array('tag_id'=>'tag_id'),'through'=>'collections_tags'),
'game_tags'=>array(self::HAS_MANY, 'GameTags',array('tag_id'=>'tag_id'), 'through'=>'tags'),
'top_coll_games'=>array(self::HAS_MANY, 'Game',
array('game_id'=>'game_id'),
'through'=>'game_tags',
'order'=>'views DESC',
'limit'=>3
)
I get the games for collection with:
$collection->top_coll_games
When there is a game that matches 2 or more tags, the query returns: game1,game1,game2 and the $collection->top_coll_games has two values because the game1.
How can I fetch from db without repetition with relations?
thank you.