Trouble with Class::DBI

T

Tore Aursand

Hi!

After being recommended this module for the past few weeks, I gave it
another look. The module itself looks very good, but I have a few
problems making it work with my "complex" data structures (which
aren't all that complex, really).

I have created a utility which converts Gedcom (genealogical) data to
a MySQL database. As it's pretty common in genealogy that one
individual can have more than one name, and I wanted to save as much
space as possible, I came up with the following tables;

individual
----------
individual_id mediumint unsigned not null,
sex char(1) default '?' not null,
modified date not null

individual_name
---------------
individual_id mediumint unsigned not null, /* references
'individual' */
given_names_id mediumint unsigned not null, /* references 'name'
*/
surname_id mediumint unsigned not null, /* references 'name'
*/
is_primary tinyint unsigned default 0 not null

name
----
name_id mediumint unsigned auto_increment primary key,
name varchar(255) not null

Getting an individual's name from this is fairly simple with an SQL
query:

SELECT gn.name as given_names,
sn.name as surname
FROM name gn,
name sn,
individual_name ina
WHERE ina.individual_id = ?
AND ina.given_names_id = gn.name_id
AND ina.surname_id = sn.name_id

Trying to represent these tables by using Class::DBI seems harder,
though, and I've been forced to look into Class::DBI::Join to make
this 'many-to-many' relationship work.

However - it doesn't work, and I really don't have a clue what to do.
Maybe I should try with something easier, I won't. :) Here are the
Class::DBI classes I've made so far:

package Individual;
use strict;
use warnings;
use base 'TestDBI';

Individual->table( 'individual' );
Individual->columns( All => qw(individual_id sex modified) );


package Name;
use strict;
use warnings;
use base 'TestDBI';

Name->table( 'name' );
Name->columns( All => qw(name_id name) );


package IndividualName;
use strict;
use warnings;
use base 'TestDBI';

IndividualName->table( 'individual_name' );
IndividualName->columns( All => qw(individual_id given_names_id
surname_id) );

Can anyone please help me out there? All help is greatly appreciated!

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top