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

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

From: Perrin Harkins
Subject: Re: Question on how to implement Class::DBI with crossover tables..
Date: 21:54 on 02 Mar 2005
On Wed, 2005-03-02 at 13:23 -0800, d. Taylor Singletary wrote:
> That won't quite work though, beause the Vendor table has no reference
> to CTCTID. The connection to a Contact is through another table, one
> that I'd like to abstract into not having to deal with.

I think you're just getting confused by the package name he chose.  In
this example, Vendor::Contact is a class for your "crossover" table, not
for contacts.  It links Vendor and Contact.

> Right now, I could do this:
> 
> Vendor->has_many(crossovers=>['Vendor::Crossover'=>'VNDRID']);
> 
> and
> 
> Vendor::Crossover->has_many(contacts=>['Vendor::Contact'=>'CTCTID']);

That's exactly what his example was doing.

This works, although it's somewhat inefficient in how it accesses the
database.

> but I want the crossover table to be automatically populated just by
> editing/adding the Vendor::Contact and Vendor records.

How would it know which vendor to connect to which contact?

There is an add_to_* method that gets created by the has_many
declaration, which would allow you to say something like this:

$vendor->add_to_contacts({
    contact => $contact
});

That would create the Vendor::Crossover row to link them.

- Perrin

Re: Question on how to implement Class::DBI with crossover tables..
Perrin Harkins 21:54 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