[Dbix-class] Self join for hierarchy

Bill Moseley moseley at hank.org
Wed Aug 21 22:17:47 GMT 2013


On Wed, Aug 21, 2013 at 2:55 PM, Oleg Kostyuk <cub.uanic at gmail.com> wrote:

> Btw, to store hierarchical structures you can re-use already existing
> modules:
> http://search.cpan.org/search?query=3DDBIx%3A%3AClass%3A%3ATree&mode=3Dall
>

Thanks.  I have looked at those in the past.   This current case I have is
pretty simple where I have a fixed depth and where I could make a single db
query instead of multiple queries (as in this method from
DBIx::Class::Tree::AdjacencyList).


sub ancestors {
    my $self =3D shift;
    my @ancestors =3D ();
    my $rec =3D $self;
    while ($rec =3D $rec->parent) {
      push(@ancestors, $rec);
    }
    return @ancestors;
}

Which approach is best is up for debate (and review by our DBA...).



-- =

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


More information about the DBIx-Class mailing list