In my database I have 5 tables:
Every game has many tags, collection has many tags. If i take a collection, I can find its games using the collection's tags.
I'm trying to perform this task with yii relations:
//in Collection's relations:
'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 a $collection and try this:
echo "collection ".$collection->name.": (id=".$collection->coll_id.") has ".count($collection->tags)."tags\n";
echo count($coll->games);//error here
and get an error
What is wrong in the relations?
As you may see here: http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through, the correct declaration of that relation would be as follows:
'games'=>array(self::HAS_MANY, 'Game', array('tag_id'=>'id'), 'through'=>'tags')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With