View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Arthur Axel "fREW" Schmidt > DBIx-Class-MaterializedPath-0.002001 > DBIx::Class::MaterializedPath



Annotate this POD


View/Report Bugs
Module Version: 0.002001   Source  


DBIx::Class::MaterializedPath - efficiently retrieve and search trees with DBIx::Class


version 0.002001


 package A::Schema::Result::Category;

 use strict;
 use warnings;

 use base 'DBIx::Class::Core';



    id => {
       data_type => 'int',
       is_auto_increment => 1,

    parent_id => {
       data_type => 'int',
       is_nullable => 1, # root

    parent_path => {
       data_type => 'varchar',
       size      => 256,
       is_nullable => 1,

    name => {
       data_type => 'varchar',
       size      => 256,


   parent_category => 'A::Schema::Result::Category', 'parent_id'

   child_categories => 'A::Schema::Result::Category', 'parent_id'

 sub materialized_path_columns {
    return {
       parent => {
          parent_column                => 'parent_id',
          parent_fk_column             => 'id',
          materialized_path_column     => 'parent_path',
          include_self_in_path         => 1,
          include_self_in_reverse_path => 1,
          separator                    => '/',
          parent_relationship          => 'parent_category',
          children_relationship        => 'child_categories',
          full_path                    => 'ancestors',
          reverse_full_path            => 'descendants',



 my $child_rows = $row->descendants;

or better yet

 my $awesome_kids = $rs->search({ awesome => 1 })


Materialized path is a way to store trees in relational databases that results in very efficient retrieval, at the expense of space and more write-time queries.

This module makes using matpaths easy. The interface is somewhat unusual, but the benefit is that it creates actual relationships for the both directions of the tree, allowing you to use the powerful querying DBIx::Class already gives you.

The first strange part of the interface is that the call to load_components must come after the call to table. The next strange bit is that the way you define all of the metadata about your matpath is by defining a subroutine called materialized_path_columns. The subroutine must return a hashref where the key is name of your path (currently unused) and the value is the metadata for the path. Here are the parts that need to be defined in the metadata:


Arthur Axel "fREW" Schmidt <>


This software is copyright (c) 2014 by Arthur Axel "fREW" Schmidt.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: