[Dbix-class] Self join for hierarchy

Bill Moseley moseley at hank.org
Wed Aug 21 20:52:31 GMT 2013


I have a table with a self-referencing parent column.  The depth of any
hierarchy is limited so I can write a join to fetch all the parents.

For example, if the table folder has a parent column:

select
    f.id,
    p0.id as parent0,
    p1.id as parent1,
    p2.id as parent2
from
    folder f
    left join folder p0 on p0.id =3D f.parent
    left join folder p1 on p1.id =3D p0.parent
    left join folder p2 on p2.id =3D p1.parent
where
    f.id =3D ?


I know I can specify a join multiple times

    join =3D> [ 'parent', 'parent', 'parent' ]

and DBIC will create separate aliases but they all join to the same "base"
table.   But, I need to join like above.

Is there a way to specify these joins or do I need to use a virtual view?


-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130821/968=
1d3bc/attachment.htm


More information about the DBIx-Class mailing list