Re: composite primary key in might_have relationship

[prev] [thread] [next] [Date index for 2005/04/28]

From: Peter Speltz
Subject: Re: composite primary key in might_have relationship
Date: 01:58 on 28 Apr 2005
--- H S <haadyai@xxxxx.xxx> wrote:
> Hi,
> 
> I am not sure this is do-able.  Any suggestions?
> 
> I have two objects:  eventpost and eventdatename2.   Eventpost has two
> FK fields that are composite primary keys  in eventdatename2.  I use
> might_have as a relationship. Is that right? 

MightHave only supports single PKs.  Easiest thing may be to make a single PK
for the table.  

Another thing, i'm confused which way your relationship goes. I think you have
it backwards. In MightHaves the PK of one class is stored in the table on right
side of relationship.  For HasA its the opposite.

So if you have this:

Eventpost->might_have(eventdatename2 => ...);  

Then eventdatename2 table has the single eventpost key stored as an FK in it.
If eventpost has the FK's as you said then it should be:

EventDateName2->might_have(eventpost => ..);

so you may have your relationship backwards but neverthelese multi keys won't
work .


> eventdatename2 object and it gives me  this error
> 
> BatchEvent::DateName2->retrieve(1501811) parameters don't include
> values for all primary key columns (event_id name2_sequence) at
> /dssweb/local-perl/lib/site_perl/5.8.3/Class/DBI/Relationship/MightHave.pm
> line 46
> 
> Thanks,
> Isarin
> 
> ============================================================
> package BatchEvent::Post; 
>  use base 'My::DBI'; 
> use Class::DBI::Pager; 
>  
> __PACKAGE__->table('batchEventPost'); 
> __PACKAGE__->columns( Primary    => qw/eventpost_id/ ); 
> __PACKAGE__->columns( Essential  => qw/event_id post_time
> cancel_sequence name2_sequence/ );
> __PACKAGE__->has_a( event_id  => 'BatchEvent::Descriptive' ); 
> __PACKAGE__->might_have( datename2  => 'BatchEvent::DateName2' =>
> qw/days name2/);
> 
> 
> package BatchEvent::DateName2; 
> use base 'My::DBI'; 
> __PACKAGE__->table('batchEventDateName2'); 
> __PACKAGE__->columns( Primary    => qw/event_id name2_sequence/ ); 
> __PACKAGE__->columns( Essential  => qw/days name2/ );
> 

pjs

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: composite primary key in might_have relationship
Peter Speltz 01:58 on 28 Apr 2005

Generated at 10:24 on 04 May 2005 by mariachi v0.52