Re: Threaded posts with a single table

[prev] [thread] [next] [Date index for 2004/08/13]

From:
Subject: Re: Threaded posts with a single table
Date: 01:00 on 13 Aug 2004
Thanks! That's also cool, and not unlike Simon's Mail stuff (if I'm
reading both correctly -- I didn't try out either yet).

I ended up with a recursive call for displaying them, mostly ignorant of
their place in the whole thread. I put together a short, and I hope clean.
example of the code and put it on the Kwiki here:
http://www.class-dbi.com/cgi-bin/wiki/index.cgi?SimpleThreadedWebPosts
There's a live cgi of the code linked there which is up when my home box
is (1/2 the day or more).

-ashley

> jinx@xxxxxxx.xxx wrote:
>>>On Wed, 2004-08-04 at 17:10, jinx@xxxxxxx.xxx wrote:
>>>>__PACKAGE__->might_have(parent => __PACKAGE__);
>>>>__PACKAGE__->has_many(replies => __PACKAGE__);
>>>
>>>I would change that might_have to this:
>>>__PACKAGE__->has_a(parent => __PACKAGE__);
>> Sure thing. I had it that way first but wasn't sure since a post could
>> be original (parentless).
>>
>>>I also like the explicit form of has_many instead of the magical form
>>> you're using there:
>>>__PACKAGE__->has_many(replies => __PACKAGE__, 'parent');
This changes back in the example b/c of the order_by {}.
>>>
> This snippet might also be useful to you.. It pulls the entire tree both
>  ways
> #
> # this application's parents
> sub parents($) {
>      my $self=shift;
>      my @application=@_;
>      my @parents;
>      my @parentspassed;
>      my %parents;
>
>      push @parents, $self;
>      while (@parents) {
>          my $pid=pop @parents;
>          my $parent = $pid->application_parent;
>          if (defined($parent)) {
>              next if ($parents{$parent->id}) ;
>
>              $parents{$parent->id} = $parent;
>              push @parents, $parent;
>              push @parentspassed, $parent;
>          }
>      }
>      return reverse @parentspassed;
> }
> #
> # this applications children
> # (so you can figure out what needs updating)
> sub children($) {
>      my $self=shift;
>      my @application=@_;
>      my @children;
>      my @childrenpassed;
>      my %children;
>
>      push @children , $self;
>      while (@children) {
>          my $pid=pop @children;
>          my @childs =
> Nagios::Application->search({application_parent=>$pid});
>          foreach my $child (@childs) {
>              next if ($children{$child->id});
>              push @children, $child;
>              push @childrenpassed, $child;
>              $children{$child->id} = $child;
>          }
>      }
>      return @childrenpassed;
> }
> #



Re: Threaded posts with a single table
Simon Cozens 21:14 on 04 Aug 2004

Re: Threaded posts with a single table
Perrin Harkins 21:21 on 04 Aug 2004

Re: Threaded posts with a single table
Ian Holsman 21:45 on 12 Aug 2004

Re: Threaded posts with a single table
01:00 on 13 Aug 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52