1
我做了很多HAS_MANY关系,但..这一次,它不想工作,我不知道为什么。Yii has_many关系失败 - 列未找到:1054未知列
我有两个型号:
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'
我也尝试添加 '指数'=> '身份证' 的关系,而且..没有变化。
怎么了?
在哪个文件中,您试图拨打电话“$ mpContests = $ this-> mpContests;” – 2014-09-24 17:00:13
我尝试在比赛模型中调用此函数.. – Delphine 2014-09-25 07:49:35