Evil Attraction has asked for the wisdom of the Perl Monks concerning the following question:
person_id mediumint unsigned auto_increment primary key, sex char(1) default '?' not null, modified date not null
name_id mediumint unsigned auto_increment primary key, name varchar(255) not null
person mediumint unsigned not null, /* references 'person' */ firstname mediumint unsigned not null, /* references 'name' */ lastname mediumint unsigned not null /* references 'name' */
package Person; use strict; use warnings; use base 'My::DBI'; Person->table( 'person' ); Person->columns( All => qw(person_id sex modified) ); Person->has_many( names => 'PersonName' ); 1;
package Name; use strict; use warnings; use base 'My::DBI'; Name->table( 'name' ); Name->columns( All => qw(name_id name) ); 1;
package PersonName; use strict; use warnings; use base 'My::DBI'; PersonName->table( 'person_name' ); PersonName->columns( All => qw(person firstname name) ); PersonName->has_a( firstname => 'Name' ); PersonName->has_a( lastname => 'Name' );
#!/usr/bin/perl # use strict; use warnings; use Person; my $Person = Person->retrieve( 1 ); my $names = $Person->names(); while ( my $Name = $names->next() ) { print $Name->lastname()->name() . ', ' . $Name->firstname()->name( +) . "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::DBI and - possibly - complex data structures
by Ovid (Cardinal) on Sep 05, 2003 at 19:58 UTC | |
by Evil Attraction (Novice) on Sep 06, 2003 at 00:06 UTC | |
|
Re: Class::DBI and - possibly - complex data structures
by perrin (Chancellor) on Sep 05, 2003 at 20:29 UTC | |
|
(OT)Re: Class::DBI and - possibly - complex data structures
by LameNerd (Hermit) on Sep 05, 2003 at 20:39 UTC |