When selecting rows using activerecord, sometimes I need to join secondary tables to the primary table rows. However, I don’t necessarily need all fields from these secondary tables.
I tried selecting only the fields I want:
Customer::find()->select(['customer.id','customer.firstname','customer.surname','organization.name'])->where(['active' => true])->joinWith(['role_history' => function (\yii\db\ActiveQuery $query) { $query->andWhere('date_end IS NULL');}, 'role_history.organization'])->asArray()->all()
This selects id, firstname and surname from the customer table, however, the resulting array still contains the full fields of the role_history and organization tables. Is there a way to omit those unwanted fields?