Select specific columns from related table

Hi,

I have the following query and it is working fine:


$cursor = Cursor::find()

    ->with('idJob')

    ->orderBy('job_start')

    ->one();

The question is:

How to pick only specific columns from related table ‘idJob’ rather than all in a purpose to optimize query?

In case of Yii v.1 it would be like this:


'with' => [

    'idJob' => [

        'select' => ['column1', 'column2']

    ]

]

but I can’t find appropriate syntax in case of Yii v.2.

Any idea?

I’ve got it:


$cursor = Cursor::find()

    ->with([

        'idJob' => function($query){

            $query->select('status'); //this will select only 'status' column from related table 'idJob'

        }

    ])

    ->orderBy('job_start')

    ->one();