multi-column PK and has_many
[prev]
[thread]
[next]
[Date index for 2005/04/20]
I have two tables from an existing schema that I want to set up a
relationship between. Table A has a single column primary key (call it
ta_id). Table B has a 3-column primary key, and one of those columns is
ta_id from Table A. This is the column that relates these two tables.
Any particular ta_id can occur many times in Table B (hence the
multi-column primary key) and so the usual has_a/might_have relationship
that I would use for a primary key shared between two tables doesn't
work. Also a has_a/has_many tries to inflate the ta_id in the Table B
object and that's a bad thing. I want to be able to return an instance
of Table B, but with only a limited number of it's fields, but has_many
doesn't seem to offer me the option of listing @feilds_to_import like
might_have does - Music::CD->might_have(method_name => Class =>
(@fields_to_import));
Shown below are my actual tables and the Classes that I have set up to
represent them. The two commented perl lines are the ones dealing with
the relationship I'm discussing. The has_many as shown calls a method
on the Table B object. I need an instance.
Any thoughts???
Seqfeature Table (aka Table A)
------------------------------
seqfeature_id integer PRIMARY KEY # aka ta_id
bioentry_id integer UNIQUE NOT NULL
type_term_id integer UNIQUE NOT NULL
source_term_id integer UNIQUE NOT NULL
display_name varchar(64)
rank integer UNIQUE NOT NULL
Seqfeature_qualifier_value Table (aka Table B)
seqfeature_id integer PRIMARY KEY #aka ta_id
term_id integer PRIMARY KEY
rank integer PRIMARY KEY
value text NOT NULL
package Recode::SeqFeature_QV;
use base 'Recode::RecodeDB';
Recode::SeqFeature_QV->table('seqfeature_qualifier_value');
Recode::SeqFeature_QV->columns(Primary => qw/seqfeature_id term_id rank/);
Recode::SeqFeature_QV->columns(Others => qw/value/);
#Recode::SeqFeature_QV->has_a(seqfeature_id => 'Recode::SeqFeature');
Recode::SeqFeature_QV->has_a(term_id => 'Recode::Term');
###########################################################################################################
package Recode::SeqFeature;
use base 'Recode::RecodeDB';
Recode::SeqFeature->table('seqfeature');
Recode::SeqFeature->columns(All => qw/ seqfeature_id bioentry_id
type_term_id source_term_id display_name rank/);
Recode::SeqFeature->has_a(bioentry_id => 'Recode::Bioentry');
Recode::SeqFeature->has_a(type_term_id => 'Recode::Term');
Recode::SeqFeature->has_a(source_term_id => 'Recode::Term');
#Recode::SeqFeature->has_many(seqfeature_qvs => [Recode::SeqFeature_QV
=> 'term_id']);
Recode::SeqFeature->might_have(location_id => [Recode::Location =>
'seqfeature_id']);
|
(message missing)
|