I am using yii2 framework and trying to join multiple tables.
I have managed to join 3 tables together but i am not clear how to extend this to 4 tables.
I joined three tables as follows >>>
//In Tasks Model
public function getLocation()
{
return $this->hasOne(Locations::className(),
['id' => 'location_id']);
}
//in current Model
public function getLocation()
{
return $this->hasOne(Tasks::className(),['id'=>'task_id'])
->with(['location']);
}
//then in grid view
....
'columns' => [
[
....
[
class' => 'kartik\grid\DataColumn',
'label' => 'Name',
'value' => 'tasks.location.name',
],
....
So that works fine, however i now want to join an additional table related to locations. the join would be locations.task_group_id = task_group.id. Full join as follows
**** I succeeded with this above ****
responses.task_id = tasks..id
tasks.location_id = locations.id
locations->name (name being the field in the locations table)
How do I do this?
responses.task_id = tasks..id
tasks.location_id = locations.id
locations.task_group.id = task_group.id
task_group->name (name being the field in the task_group table)