我有两个模型:
class Tag extends CActiveRecord {
//// ......
public function defaultScope(){
return array(
'condition' => 'class_name = :class_name',
'params' => array(':class_name' => get_class($this))
);
}
public function relations(){
return array(
'videos' => array(self::MANY_MANY, 'Video', 'tags_videos(tag_id, video_id)')
);
}
//// ......
}
class Video extends CActiveRecord {
//// .......
public function relations(){
return array(
'tags' => array(self::MANY_MANY, 'Tag', 'tags_videos(video_id, tag_id)')
);
}
//// .......
}
当我这样做时$video_instance->tags
,我收到了这个错误:
exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number. The SQL statement executed was: SELECT `tags`.`id` AS `t1_c0`, `tags`.`name` AS `t1_c1`, `tags`.`orig_name` AS `t1_c2`, `tags`.`slug` AS `t1_c3`, `tags`.`flags` AS `t1_c4`, `tags`.`class_name` AS `t1_c5`, `tags`.`created_at` AS `t1_c6` FROM `tags` `tags` INNER JOIN `tags_videos` `tags_tags` ON (`tags_tags`.`video_id`=:ypl0) AND (`tags`.`id`=`tags_tags`.`tag_id`) AND (class_name = :class_name) WHERE (class_name = :class_name)' in /srv/http/yii-1.1.12.b600af/framework/db/CDbCommand.php:528
我的问题是:为什么我的默认范围两次应用于查询(在 WHERE 和 ON 中),我该如何解决这个问题?
Yii 版本:1.1.12.b600af PHP:5.4.8