On 12/28/05, Kim Ryan <[EMAIL PROTECTED]> wrote:
> I have a database where the primary key is defined over several columns.
>
> I have used  the Class:DBI method to define by primary key
> MyDB::Results->columns(Primary => qw/version  resolution precision/);
> MyDB::Results->columns(Other => qw/a b c/);
>
> My problem is in constructing the one to one join with another table.
> When the primary key is a single column called id, there is no problem
> MyDB::Results->has_a(suite => "MyDB::Suites");
>

> Now I want to join two tables that use the same multi column primary key
> How to I define the join columns. In the example above, I just use the
> column
> name, suite but cannot use that for several columns.

First, the has_a relationship is not one to one. It is many to one --
Ie many Beers can have the same Brewery. You can use it like one to
one though (if you add a cascade delete) .

Your problem  is a perfect might_have problem except with multi column
keys. See the docs on might_have if you have not.  However they do not
support MKs :(   But perhaps you could write one that did ?

As it is now, A custom method would be easy to write that uses a search.

# Get the related row from Results table
sub MyDB::Problem::results {
    my ($obj) = shift;
    return MyDB::Results->search( version => $obj->version,  
resolution => $obj->resolution,  precision => $obj->precision);
}


> And what gets displayed
> in the join link, as it cannot simply display the column contents?

What do you mean by that?  Basically in all the links Maypole
templates make they stringify the object for the content of the link. 
You make a "stringify_self" method to display what you want.

> Do I need to have a named key. (I don't think you can alter the name of the
> primary key).

Not sure what you mean here.   Working on new apps so far I have
always made it a point to use single PKs. That way they are there when
I need them and I can still treat other columns as part of a Key when
I need to.  However I probably have just not been doing this long
enough to discover the benefit of true Mult column primary keys.

 HTH.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users

Reply via email to