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)
Each game has many tags, the collection has many tags. If I take a collection, I can find her games using collection tags.
I am trying to accomplish this task using yii relationships:
'tags'=>array(self::MANY_MANY, 'Tag', 'collections_tags(coll_id,tag_id)'),
'games'=>array(self::HAS_MANY, 'Game','tag_id', 'through'=>'tags')
Then I get $ collection and try:
echo "collection ".$collection->name.": (id=".$collection->coll_id.") has ".count($collection->tags)."tags\n";
echo count($coll->games);
and get an error.
What's wrong with the relationship?
source
share