er.ravi
(Er Ravi62)
1
Hi there,
Please suggest me the preferred way to fetch only the selected column from the related table.Please have a look at the following piece of code:
$querydata = Model::find()->joinwith(’-relation-with-demotable’)->all();
Now,
If the demotable has three fields namely:demoId,demoName,demoDesc.
I only need demoName from the related table.
What should be my query now.
You can use the following construction:
User::find()->select(['demoName]);
Where User is user model.
bobonov
(Bobonov)
3
I would add to use also
$querydata = Model::find()->select([‘demoName])->joinwith(’-relation-with-demotable’)->asArray()->all();
Since you need only this field probably you do not need the ActiveRecord object
With asArray you get back an array which has a much smaller memory footprint.