active-record
active-record copied to clipboard
Add support polymorphic relations
In 2.0, it is very upsetting that there are no polymorphic relations out of the box. It would be cool to be able to use such relations. It would be very nice to use something like this:
return $this->hasMany(Comment::class, ['entity_id' => 'id'])
->polyTo(['entity_type'], static::class);
Here is an implementation from Humhub: https://github.com/humhub/humhub/blob/4ea2e27bf7dafcc968c52569b3cbd760b0fa53d5/protected/humhub/components/behaviors/PolymorphicRelation.php
https://github.com/Oxyaction/yii2-polymorphic-relation-behavior