How to use constant in the ON condition in Yii2 hasMany relation
In this case you can modify ON condition with andOnCondition method: public function getImages() { return $this->hasMany(RecipeImage::className(), [‘imageable_id’ => ‘id’]) ->andOnCondition([‘imageable_type’ => ‘Person’]); } Official docs: andOnCondition: