self join on table

[prev] [thread] [next] [Date index for 2004/06/25]

From: steve shapero
Subject: self join on table
Date: 19:37 on 25 Jun 2004
hello all--

time for today's design question.

i have a table, let's call it genre, that looks like this:

table genre (
	genreid primary key,
	name 
	parentgenreid 
)

i've set up my Genre class to look like this:

...usual setup stuff...

__PACKAGE__->has_a(parentgenreid => 'SDMS::Genre' => 'parentgenreid');

then in my code i can do this:

my $genres = $track->genres;
while ( my $genre = $genres->next ) {
    eval {
        print $genre->parentgenreid->name, ", ";
    };
    print $genre->name, "\n";
}

so that if the "parent" genre is defined, it will print it out,
otherwise don't barf.  this "works" in the sense that i get my desired
output.  however, i get this runtime error:

Odd number of elements in hash assignment at
/usr/lib/perl5/site_perl/5.8.1/Class/DBI/Relationship/HasA.pm line 16.

i tried all the other examples of doing has_a that i could find/think
of, but only the one shown above produced the desired result.

questions:
1. am i designing this in a stupid way?
2. if not, how do i get the desired output without the error/warning?

thanks!
steve






self join on table
steve shapero 19:37 on 25 Jun 2004

Re: self join on table
Tony Bowden 00:12 on 26 Jun 2004

Re: self join on table
steve shapero 00:51 on 26 Jun 2004

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