Relations through via() problem

Hi.

I am rewriting one of my projects from Yii to Yii2 and suddenly run into trouble with complex relations. In yii1, i can make chain relations inside same AR model with ‘through’ option. In yii2 I find this functionality realized with via() method in relation definition.

However, after rewriting relations I got

[color="#FF0000"]Getting unknown property: app\modules\contractors\models\Tenders::groupId[/color]

For some reason Yii tried to find link-field (groupId) inside primary model (Tenders). And I expected from Yii to get it from relation model (TendersDirections) that should be linked through via() method.

If i call CompaniesDirections or Directions relations directly, everything works nice.

At this point I try to understand is Yii2 support long chains through via() links inside model, or this is bug.




Tenders::find()->with(['companies'])->where(['id' => array_keys($selection)])->all();






 public function getDirections()

    {

        return $this->hasMany(TendersDirections::className(), ['tenderId' => 'id']);

    }


    public function getCompaniesDirections()

    {

        return $this->hasMany(CompaniesDirections::className(), ['groupId' => 'groupId'])

                        ->via('directions');

    }


    public function getCompanies()

    {

        return $this->hasMany(Companies::className(), ['id' => 'companyId'])

                        ->via('companiesDirections');

    }



Thanks