There is an Image model in which images are stored, as the name implies. Each individual image is attached to any other model by specifying the modelName and itemId fields .
I can not figure out how to make a greedy sample. For linked tables through FK, you can make selections through hasOne and hasMany , but I cannot understand how to do this without this connection. As it is a pity for each model to make one extra request.
The image module itself for yii2 downloaded and installed separately, you can look at the yii2-images repository here .
onCondition
- Bookinreturn $this->hasOne(Image::className(), ['itemId' => 'id']) ->onCondition(['modelName' => $this->tableName()]);
- arkadij_ok