If you're also using DBIx::Class, this half-pseudo code does the trick. I am running this for real (in three different versions, one is Class::DBI, two are Catalyst) in a couple production situations. Sorry I'm not posting the full working code but that would be a BIG amount of stuff including the DB and everything and I'm not quite ready to share it. I think I included most of the working bits. In has both posts that are threaded (like WordPress "pages," I think) and threaded comments belonging to the post.

# blog posts (also threaded) package MyApp::Schema::DB::post; use base qw/ DBIx::Class /; __PACKAGE__->load_components qw( PK::Auto Core ); __PACKAGE__->table('post'); # ... missing some regular set-up code __PACKAGE__->add_columns(qw/ id user parent title body golive created updated /); __PACKAGE__->belongs_to('parent' => 'MyApp::Schema::DB::post'); __PACKAGE__->has_many('children' => 'MyApp::Schema::DB::post' => 'pare +nt', { order_by => "golive" } ); # ... missing some other methods sub parents { my ( $self, @parents ) = @_; my $parent = $self->parent; return @parents unless $parent; unshift @parents, $parent; die "Unterminating lineage loop suspected!" if @parents > 50; $parent->parents(@parents); } # comments ... threaded, attached either to a # parent comment or directly to a post package MyApp::Schema::DB::comment; use base qw/ DBIx::Class /; __PACKAGE__->load_components qw( PK::Auto Core ); __PACKAGE__->table('comment'); __PACKAGE__->add_columns(qw/ id post user parent title body created updated /); __PACKAGE__->belongs_to('post' => 'Yesh::Schema::DB::post'); __PACKAGE__->belongs_to('parent' => 'MyApp::Schema::DB::comment'); __PACKAGE__->has_many('replies' => 'MyApp::Schema::DB::comment' => 'pa +rent'); sub depth { my $self = shift; return 1 + scalar $self->parents; } sub parents { my ( $self, @parents ) = @_; my $parent = $self->parent; return @parents unless $parent; push @parents, $parent; die "Unterminating lineage loop suspected!" if @parents > 100; $parent->parents(@parents); }
Update: added a necessary "belongs_to."

In reply to Re: message board thread quandary by Your Mother
in thread message board thread quandary by stonecolddevin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.