Re: Question on how to implement Class::DBI with crossover tables..

[prev] [thread] [next] [Date index for 2005/03/02]

From: Matt S Trout
Subject: Re: Question on how to implement Class::DBI with crossover tables..
Date: 17:55 on 02 Mar 2005
On Wed, Mar 02, 2005 at 09:37:09AM -0800, d. Taylor Singletary wrote:
> 
> Hi there,
> 
> New to the list and new to Class::DBI. I've read through the
> documentation and tutorials and they all seem to assume that related
> tables/objects would have the related fields within the tables...
> 
> that doesn't make much sense. Here's the way we do relationships around
> here:
> 
> We'll have a table called CONTACT with a primary key of CTCTID.
> We'll have a table called CUSTOMER with a primary key of CSTMRID.
> We'll have a table called VENDOR with a primary key of VNDRID.
> 
> Then we'll have two crossover tables:
> XCONCUST with a primary of XCONCUSTID, with the fields CTCTID & CSTMRID
> tying the records together. 
> XCONVEN with a primary key of XCONVENID, with the fields CTCTID & VNDRID
> tying the records together.
> 
> Is it possible with Class::DBI to semi-transparently manage the
> crossover tables and still assert relationships like Vendor::Contact,
> Customer::Contact? How is that done? When accessing these objects I
> don't want to have to think about maintaining the relationships in the
> crossover tables at all. Customers can have many contacts, Vendors can
> have many contacts.

Yeah, I do this all the time. My current solution is the (not on CPAN yet)
http://trout.me.uk/perl/Class-DBI-Relationship-HasManyToMany-0.02.tar.gz
or you could have a look at the ManyMany relationship outline Tony posted
a while back (search the list archives for this one).

        -- 
            Matt S Trout            Brag sheet:    http://trout.me.uk/services.html
LAMP, Infrastructure        Contact:       services@xxxxx.xx.xx
   and Automation
     specialist                                       Do it once. Do it right.

Re: Question on how to implement Class::DBI with crossover tables..
Matt S Trout 17:55 on 02 Mar 2005

Creation of composite objects automatically
Peter Speltz 22:32 on 02 Mar 2005

Generated at 00:32 on 04 Mar 2005 by mariachi v0.52