Yii has_many关系失败-找不到列:1054未知列


Yii has_many relation failed - Column not found: 1054 Unknown column

我做了很多HAS_MANY关系,但是。。这一次,它不想工作,我不明白为什么。

我有两种型号:

Contest (id, name)MpContest (id, contest_id).

在我的数据库中,我创建了外键和主键。

竞赛班:

public function relations() {
    return array(
        'mpContests' => array(self::HAS_MANY, 'MpContest', 'contest_id'),       
    );
}

在MpContest类:

public function relations() {
    return array(
        'contest' => array(self::BELONGS_TO, 'Contest', 'contest_id'),
        'contestType' => array(self::BELONGS_TO, 'ContestType', 'contest_type'),
    );
}

当我试图从比赛中获得相对的MpContest时,我会出错。

我试着这样做:

$mpContests = $this->mpContests;

我明白了:

CDbCommand n'a pas pu exécuter la commande SQL : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'mpContests.contest_id' in 'where clause'. The SQL statement executed was: SELECT `mpContests`.`id` AS `t1_c0`, `mpContests`.`name` AS `t1_c1`, `mpContests`.`date_start` AS `t1_c2`, `mpContests`.`date_end` AS `t1_c3`, `mpContests`.`date_start_post` AS `t1_c4`, `mpContests`.`date_end_post` AS `t1_c5` FROM `contest` `mpContests` WHERE (`mpContests`.`contest_id`=:ypl0). Bound with :ypl0='1' 

我还尝试添加"index"=>"id"作为relation,但是。。没有什么变化。

怎么了?

Omg!我发现了它不想工作的原因。。

我在MpContest课上拼错了表名。。

这是我的错。很抱歉我考虑不周,也许其他人也会有同样的问题。