I also have problems with this. Here is my workaround for the hasOne () relation.
public function getGroup() { if(isset(static::$_getGroup[$this->id])) { return static::$_getGroup[$this->id]; } $Group = $this->hasOne(BillChargesGroup::className(), ['id' => 'group_id'])->one(); static::$_getGroup[$this->id] = $Group; return $Group; }
I only want to cache data for the current request, so this works. However, since I use ->one(); , it does not return an ActiveQuery object if we call $model->getGroup() (which I found useful for extending queries)
Unfortunately, if I return an ActiveQuery object, Yii2 does some βmagicβ on it and always does SELECT *, which I cannot control.
source share