Re: Threaded posts with a single table

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

From: Perrin Harkins
Subject: Re: Threaded posts with a single table
Date: 21:21 on 04 Aug 2004
On Wed, 2004-08-04 at 17:10, jinx@xxxxxxx.xxx wrote:
> Is it possible to use CDBI this way?
> 
> Given a table like:
>  CREATE TABLE post
>    (
>     id     INT(9) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
>     parent INT(9),  # <-- this is just another post.id
>     text   TEXT,
>     etc    ...
>     );
> 
> ...then...
> 
> package My::Post;
> use base qw( My::CDBI );
> 
> __PACKAGE__->table('post');
> __PACKAGE__->columns(All => qw( id parent text etc ) );
> __PACKAGE__->might_have(parent => __PACKAGE__);
> __PACKAGE__->has_many(replies => __PACKAGE__);

I would change that might_have to this:
__PACKAGE__->has_a(parent => __PACKAGE__);

I also like the explicit form of has_many instead of the magical form
you're using there:
__PACKAGE__->has_many(replies => __PACKAGE__, 'parent');

> So, the "parent" I can see working fine. It's just pointing to a "foreign"
> id in its own table. It's the "replies" that obviously won't work that
> way.

What makes you think that?

- Perrin

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

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