Many to Many relationships

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

From: Bryon Bean
Subject: Many to Many relationships
Date: 20:38 on 06 May 2004
Hi,

I'm having a problem figuring out why I'm only getting the first row
returned multiple times for a many to many table. Could someone please point
me in the right direction? TIA...

package ShowdateArtist;
__PACKAGE__->table('showdate_artist');
__PACKAGE__->columns( All => qw/ showdate_id artist_id order_of_appearance
/ );
__PACKAGE__->has_a( showdate_id => 'Showdate' );
__PACKAGE__->has_a( artist_id   => 'Artists'   );

package Showdate;
__PACKAGE__->table('showdate');
__PACKAGE__->columns( All => qw/ id showdate ticketurl ages time cover
headline text confirmed / );
__PACKAGE__->has_many( artist => [ ShowdateArtist => 'artist_id' ]  );

package Artists;
__PACKAGE__->table('artists');
__PACKAGE__->columns( All => qw/ id name url notes bio image / );
__PACKAGE__->has_many( showdate => [ ShowdateArtist => 'showdate_id' ]  );

elsewhere...

use Data::Dumper;

sub get_all_showdates{
    my $self = shift;
    my $shows = Showdate->retrieve_all();

    while( my $show = $shows->next() ){
        my @artists = $show->artists();
        print Dumper( \@artists );
    }
}

output from get_all_shows()...

$VAR1 = [
          bless( {
                   'id' => '29'
                 }, 'GigTools::Venue::DB::Artists' ),
          bless( {
                   'id' => '29'
                 }, 'GigTools::Venue::DB::Artists' ),
          bless( {
                   'id' => '29'
                 }, 'GigTools::Venue::DB::Artists' )
        ];


okay, so let's try something different...

ub get_all_showdates{
    my $self = shift;
    my $shows = Showdate->retrieve_all();

    while( my $show = $shows->next() ){
        while( my $artist = $show->artists()->next() ){
            print $artist->name() . "\n";
        }
    }
}

and the resulting output is an endless loop...

RADIOHEAD
RADIOHEAD
RADIOHEAD
RADIOHEAD
RADIOHEAD
etc...

I don't get it? <- stating the obvious :-)
________________________________________
In heaven all the interesting people are missing.
  --Friedrich Nietzsche

Many to Many relationships
Bryon Bean 20:38 on 06 May 2004

Re: Many to Many relationships
Perrin Harkins 20:37 on 06 May 2004

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