Attribute parent_id related to itself

Hi!
I have a table (id, parent_id, …) Does anyone know if it is possible to automatically generate “nested” relation to itself? The problem is that MySQL does not permit relations to itself.

For example like in all models are automatically generated arrays for related tables.
In my case I would like to access like this:

$model->parent->parent->...parent;

Gii is relying on foreign keys so no, it’s not possible to generate it autoamtically. But relation, if added manually, would work.

1 Like

Thanks Sam, this Yii2 is really neat & nice to use. Practically you can develop apps overnight :star_struck: