active-record icon indicating copy to clipboard operation
active-record copied to clipboard

Add support polymorphic relations

Open brussens opened this issue 7 years ago • 2 comments

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);

brussens avatar Oct 30 '18 23:10 brussens

Here is an implementation from Humhub: https://github.com/humhub/humhub/blob/4ea2e27bf7dafcc968c52569b3cbd760b0fa53d5/protected/humhub/components/behaviors/PolymorphicRelation.php

cebe avatar Nov 01 '18 12:11 cebe

https://github.com/Oxyaction/yii2-polymorphic-relation-behavior

rustamwin avatar Dec 13 '18 10:12 rustamwin