in reply to Class::DBI and a self-referencing many-to-many

In my Class::DBI-based link checker, I solved the problem like this:
{ package My::Link; our @ISA = qw(My::DBI); __PACKAGE__->table('link'); __PACKAGE__->columns(Primary => qw(src dst)); __PACKAGE__->has_a(src => 'My::Page'); __PACKAGE__->has_a(dst => 'My::Page'); } { package My::Page; our @ISA = qw(My::DBI); __PACKAGE__->table('page'); __PACKAGE__->columns(All => qw(location state last_status last_checked last_good last_modified) +); __PACKAGE__->has_many(inbound => 'My::Link', 'dst', { sort => 'src' +}); __PACKAGE__->has_many(outbound => 'My::Link', 'src', { sort => 'dst' + }); }
It looks close to what you did. Not sure why mine worked and yours didn't.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Class::DBI and a self-referencing many-to-many
by jgallagher (Pilgrim) on Sep 14, 2005 at 16:28 UTC

    That's pretty much identical to what I did. I even get an identical error. :-)

    My test code was:

    my $page1 = My::Page->create({ location => 'abc' }); my $page2 = $page1->add_to_inbound({ location => 'def' });

    The error I get:

    location is not a column of My::Link at /usr/lib/perl5/site_perl/5.8.6/Class/DBI/Relationship/HasMany.pm line 92

    This is with Class::DBI 3.04.

    Update:

    Maybe this is just a problem with the auto-created add_to_* method. If I:

    my $page1 = My::Page->create({ location => 'abc' }); my $page2 = My::Page->create({ location => 'def' }); My::Link->create({src => $page1, dst => $page2}); croak Dumper([$page1->inbound()], [$page1->outbound()], [$page2->inbound()], [$page2->outbound()], );

    I almost get what I expect. Should $page1->inbound() return a My::Link or an array of My::Pages?