私は2つのモデルを持っています:
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
私の質問は、なぜ私のデフォルトスコープがクエリに2回適用されるのですか(WHEREとONで)、どうすればこれを修正できますか?
Yii バージョン: 1.1.12.b600af PHP: 5.4.8