我在mysql中有一个结构:
community:
id | etc...
category:
id | community_id | etc
topic:
id | category_id | etc
所以,我在社区模型中写关系
'categories' => [self::HAS_MANY, 'Category', 'community_id'],
'topics' => [self::HAS_MANY, 'Topic', 'id', 'through' => 'categories'],
但是,关系主题不起作用,错误:order order子句中的列'id'是不明确的。
答案 0 :(得分:0)
你们的关系应该是这样的:
'categories' => array(self::HAS_MANY, 'Category', 'community_id'),
'topics' => array(self::HAS_MANY, 'Topic', array('category_id','id'), 'through' => 'categories'),