Adjustments in the population of relations

Guys, please help me with this issue. I'm not sure about it and if the PR is the best way out.

I have the following model:
```PHP
class Company extends yii\db\ActiveRecord
{
    (...)
    public function getCalendars()
    {
        return $this->hasMany(Calendar::className(), ['employeeCompany_id' => 'id'])->viaTable('EmployeeCompany', ['company_id' => 'id']);
    }

    public function getTasks()
    {
        return $this->hasMany(Task::className(), ['id' => 'task_id'])->via('calendars');
    }
}
```

Then do the following call:
```PHP
$model = Company::find()->with(['tasks', ...])->one();
```

The models of the relation `tasks` are not populated. 
However, if I remove the name of the relation of the `with()` method and subsequently get to `$model->tasks`, the data is returned correctly. 

I racked my brain to understand what was happening and after much debugging I realized that when `buildBuckets()` method was called on the population of the relation, the param `$viaLink` not contain the attribute which referred to the parent model. With these changes I did, everything worked perfectly. 

I also noticed that the `$key` variable in `getModelKey()` method was defined assuming that the variable `$model` was always an array, when in fact it can also be an object.