[CDBI] has_many self reference

Hunter Thomas archangelq at archangelq.net
Sun Feb 5 15:37:18 GMT 2006


So, I'm trying to do this:

Table def:
CREATE TABLE entry {
id INT PRIMARY KEY,
parent INT
}

Perl code:
package Entry;
use base 'My::DB'; #inherits from Class::DBI::AutoLoader
__PACKAGE__->has_a(parent => 'Entry');
__PACKAGE__->has_many(children => ['Entry', 'parent']);
1;

And I get the error:
Couldn't load "Entry", "Can't locate object method "meta_info" via 
package "Entry" at 
/usr/local/lib/perl5/site_perl/5.8.7/Class/DBI/Relationship/HasMany.pm 
line 34

I've been playing with this, trying to put it after the 1; with the 
__PACKAGE__ as Entry->, and none of it is working, I keep getting the same.

I have collapsed the info above, by the way. I'm trying to make a table 
that stores both the main entries and any comments for a blog (yes, 
another blog, sorry), and this just seemed like the most natural way to 
model it. Any thoughts?




More information about the ClassDBI mailing list