Re: Threaded posts with a single table
[prev]
[thread]
[next]
[Date index for 2004/08/04]
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
Perrin Harkins 21:21 on 04 Aug 2004
|