To get related field in model first of all your must have relation model TblChecks
define relation in model TblTrucks
acording to documentation
In you case it will be some like that:
public function getTblChecks()
{
return $this->hasOne(TblChecks::className(), ['truck_id' => 'id']);
//or, depending on the type of relation (on-to-one or one-to-maty)
return $this->hasMany(TblChecks::className(), ['truck_id' => 'id']);
}
Than use method joinWith
:
$trucks = TblTrucks::find()
->joinWith(['tblChecks'])
->Where(["town"=>$town])
->andWhere(["truck_status"=>6])
->andWhere(["between","tbl_trucks.created_at", $ts1, $ts2 ]);
And then you can get relation field just call it:
$models = $provider->getModels();
$models[index]->tblChecks->needed_field
But if you need just array of modesl acording to your query you dont have to use ActiveDataProvider
just call method all()
For example:
$trucks = TblTrucks::find()
->joinWith(['tblChecks'])
->Where(["town"=>$town])
->andWhere(["truck_status"=>6])
->andWhere(["between","tbl_trucks.created_at", $ts1, $ts2 ])->all();
And in var $trucks
you will have array of models TblTrucks
with relation models (TblChecks
in this case) acording to your query.
$model->getChecks()
on each model you get from$provider->getModels()
assuming you havegetChecks()
method which returns related records in yourTblTrucks
class – ArtOsitblTrucks
model. – Insane Skull