Php 生成连接表关系的Yii2中的Gii积垢

Php 生成连接表关系的Yii2中的Gii积垢,php,mysql,yii2,Php,Mysql,Yii2,我有三个模型:Person、Feature和PersonFeature。PersonFeature是一个包含两个外键的连接表,person_id引用person表中的id,feature_id引用feature表中的id 我的问题是Yii2中的Gii是否生成所有相关关系。这是三个模型中每个模型的关系 人: public function getPersonfeatures() { return $this->hasMany(Personfeature::className(), [

我有三个模型:Person、Feature和PersonFeature。PersonFeature是一个包含两个外键的连接表,person_id引用person表中的id,feature_id引用feature表中的id

我的问题是Yii2中的Gii是否生成所有相关关系。这是三个模型中每个模型的关系

人:

public function getPersonfeatures()
{
    return $this->hasMany(Personfeature::className(), ['personid' => 'id']);
}
特色:

public function getPersonfeatures()
{
    return $this->hasMany(Personfeature::className(), ['featureid' => 'id']);
}
人物特征:

public function getPerson()
{
    return $this->hasOne(Person::className(), ['id' => 'personid']);
}
public function getFeature()
{
    return $this->hasOne(Feature::className(), ['id' => 'featureid']);
}
但当我浏览其他帖子时,我发现存在一个“viaTable”操作,例如:

public function getPerson() {
return $this->hasMany(Person::className(), ['id' => 'personid'])
    ->viaTable('personfeature', ['featureid' => 'id']);}
所以基本上我的问题是,Yii应该为我生成这个吗?或者我可以手动添加它吗


Cheers

viaTable的最后一个函数是一个多对多关系,该函数可以与任何其他关系函数一样使用,例如在->with查询中

连接表不需要模型,除非您想将其用于其他用途

希望这有帮助