[Dbix-class] how to handle tables with multi column foreign keys

John Napiorkowski jjn1056 at yahoo.com
Mon May 1 20:04:45 CEST 2006


Hi,

I can't find any info about using dbix::class with
tables that have multi column foreign keys.  The
documentation on how to handle multi column primary
keys is quite clear!

Here's what I am trying to do.  I have a table in
postgresql defined with the following DDL:

CREATE TABLE bookmarks
(
bookmark_id serial      NOT NULL,
document_id int         NOT NULL,
folder_id   int         NULL,	
href        varchar(99) NOT NULL,
title       varchar(64) NOT NULL,
description varchar(99) NOT NULL,


CONSTRAINT "bookmark_folder"	
   FOREIGN KEY (folder_id, document_id)
   REFERENCES folders(folder_id, document_id),
	 
CONSTRAINT "bookmark_document"	
   FOREIGN KEY (document_id)
   REFERENCES documents(document_id),
	 
CONSTRAINT "bookmark_PK" 		
   PRIMARY KEY (bookmark_id, document_id)
);

Then I have:

package MyApp::Schema::db::bookmarks::bookmarks;

use warnings;
use strict;

use base qw/MyApp::Schema::base/;

__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table('bookmarks');

__PACKAGE__->add_columns(qw/bookmark_id document_id
folder_id href title description priority/);
__PACKAGE__->set_primary_key(qw/bookmark_id
document_id/);

__PACKAGE__->belongs_to('documents'	=>
'talentspace_portal::Schema::db::bookmarks::documents');
__PACKAGE__->belongs_to('folders' 		=>
'talentspace_portal::Schema::db::bookmarks::folders');

Which is working fine for tables that have single
column foriegn keys, but with this I get an error
stating that it can't infer the correct table.

What I'd like to know before I beat on this some more
is if it is supposed to work.  That is does DBIx
support multi-column foreign keys?  If so I would
greatly appreciate anyone that made it work tossing an
example in my direction.

I can see there is quite a bit of information in the
docs for DBIx::Class:Relationship::Base, but to be
honest I'm just not getting it.

--john

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



More information about the Dbix-class mailing list