Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Greetings zigdon,

I'm still learning CBDI myself, so I don't know how helpful this will be. However, here's what I've come up with. I think the problem is with your has_many definitions for Org and PartType. The two lines should be more like:

__PACKAGE__->has_many('PartTypes' => 'MyCDBI::PartType', 'typeid');

To solve the problem, I had to rewrite ever so slightly some of your conventions (to help me mentally understand things because I'm still learning CDBI myself), so you'll want to translate this code back. However, here's the final code that does appear to work for me...

#!/usr/bin/perl use strict; use warnings; package MyCDBI; use base 'Class::DBI::mysql'; __PACKAGE__->connection('dbi:mysql:cdbi', 'gryphon', 'PASSWORD'); package MyCDBI::Org; use base 'MyCDBI'; __PACKAGE__->set_up_table('org'); __PACKAGE__->has_many('PartTypes' => 'MyCDBI::PartType', 'typeid'); package MyCDBI::PartType; use base 'MyCDBI'; __PACKAGE__->set_up_table('parttype'); __PACKAGE__->has_a('orgid' => 'MyCDBI::Org'); __PACKAGE__->has_many('PartTypes' => 'MyCDBI::OrgPart', 'typeid'); package MyCDBI::OrgPart; use base 'MyCDBI'; __PACKAGE__->set_up_table('orgpart'); __PACKAGE__->has_a('typeid' => 'MyCDBI::PartType'); package main; my $org = MyCDBI::Org->create({ orgid => 1 }); my $pt1 = MyCDBI::PartType->create({ typeid => 1, orgid => $org }); my $pt2 = MyCDBI::PartType->create({ typeid => 2, orgid => $org }); my $op1 = MyCDBI::OrgPart->create({ typeid => 1, typeid => $pt1 }); my $op2 = MyCDBI::OrgPart->create({ typeid => 2, typeid => $pt1 }); my $op3 = MyCDBI::OrgPart->create({ typeid => 3, typeid => $pt2 }); my $op4 = MyCDBI::OrgPart->create({ typeid => 4, typeid => $pt2 }); $org->delete;

And just to make sure I cover my assumptions, here's the create SQL for the database...

CREATE TABLE org ( orgid tinyint(3) unsigned NOT NULL auto_increment, PRIMARY KEY (orgid) ) TYPE=MyISAM; CREATE TABLE orgpart ( opid tinyint(3) unsigned NOT NULL auto_increment, typeid tinyint(3) unsigned default '0', PRIMARY KEY (opid) ) TYPE=MyISAM; CREATE TABLE parttype ( typeid tinyint(3) unsigned NOT NULL auto_increment, orgid tinyint(3) unsigned default '0', PRIMARY KEY (typeid) ) TYPE=MyISAM;

I hope this helps. I'm still struggling with CDBI in hopes that eventually it will be worth it.

gryphon
code('Perl') || die;


In reply to Re: Class::DBI cascading delete problem? by gryphon
in thread Class::DBI cascading delete problem? by zigdon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-19 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found