FW: many to many help

[prev] [thread] [next] [Date index for 2004/06/09]

From: Bruner, Todd
Subject: FW: many to many help
Date: 19:34 on 09 Jun 2004
OK, I now know that the XYZ::Links needs to be before XYZ::Things if they
are in the same file.  However, I still run into a problem with cascading
delete.  Namely, as coded below, the cascading delete will only delete the
rows in the Links table with srcThingId = to target, and ignores rows in the
Links table with dstThingId = to target.
Reversing the order of the has_a declarations in the XYZ::Links package,
reverse the column that is matched (ie. dstThingId now is matched instead of
srcThingId).  Any pointers or clues to how to make this work will be
appreciated.  

Todd



-----Original Message-----
From: tbruner@xxxxxx.xxx [mailto:tbruner@xxxxxx.xxx] 
Sent: Monday, June 07, 2004 8:40 AM
To: cdbi-talk@xxxxxx.xxxxx.xxx
Subject: many to many help


After reading the docs and scanning this lists archives, I am left wondering
how to accomplish the following.  

Database schema: (unessential columns omitted for brevity)

create table Things (
     ThingId integer unsigned not NULL auto_increment,
     node    varchar(80),
     ...
     primary key(ThingId)
);

create table Links (
     LinkId  integer unsigned not NULL auto_increment,
     linklable varchar(80),
     srcThingId integer unsigned,
     dstThingId integer unsigned,
     primary key (LinkId)
);

The idea for the database is to track the relationship between a set of
"Things."

I have the following set up in a package:

package XYZ::DB;
use base qw(Class::DBI);
use warnings;
XYZ::DBI->connection(connection_details_omitted);

package XYZ::Things;
use base qw(XYZ::DB);
XYZ::Things->table('Things'); XYZ::Things->columns(All=>qw(ThingId node));
XYZ::Things->has_many(links => 'XYZ::Links');

package XYZ::Links;
use base qw(XYZ::DB);
XYZ::Links->table('Links');
XYZ::Links->columns(All=>qw(LinkId linklable srcThingId dstThingId));
XYZ::Links->has_a(srcThingId => 'XYZ::Things'); XYZ::Links->has_a(dstThingId
=> 'XYZ::Things');

Now in my program I am trying to delete a thing using the following:

my $obj = XYZ::Things->retrieve("7"); # get ThingId = 7, which exists in DB
$obj->delete;

When that snippet runs, I get the following error:

things is not a column of XYZ::Links at
/usr/local/libdata/perl5/site_perl/Class/DBI/Relationship/HasMany.pm line 61

Can anyone shed some light on what I'm doing wrong?  Any help will be
appreciated.

Thanks in advance,
Todd

FW: many to many help
Bruner, Todd 19:34 on 09 Jun 2004

Re: FW: many to many help
Tony Bowden 19:44 on 09 Jun 2004

Re: FW: many to many help
Vince Veselosky 21:05 on 09 Jun 2004

Re: FW: many to many help
Tony Bowden 22:02 on 09 Jun 2004

Re: FW: many to many help
Vince Veselosky 17:48 on 15 Jun 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52