Hello Everyone,

I'm trying to accomplish something that seems entirely normal to me, but I can't easily find a way of accomplishing this with a standard Class::DBI.

I have three tables. The first (abbreviated) is something like:

create table baseitems ( id integer primary key, data text );

This table is the base for a bit of one-to-many inheritance for my second table:

create table items ( id integer, subid integer, data text, primary key (id, subid), foreign key (id) references baseitems (id) );

I believe this structure is pretty self explanitory, and represents a simple inheritance type of relationship. So far, so good. The has_a and has_many relationships for this structure were easy to come up with. The problem I have comes in when I want to make a "third-level" table that references my "second-level" table 'items'. This third table is:

create table codes ( id integer, subid integer, data text, unique (id, subid, data), foreign key (id, subid) references items(id, subid) );

I have no problem writing SQL to link all this stuff together in meaningful ways, and the approach seems valid... I haven't read much into database design, I sorta wing it, which may very well be my problem here.

I do have a problem explaining to Class::DBI that the foreign key that links a 'code' back to an item isn't a single column; the has_a method call only seems to accept a single column.. and I don't see any other way to establish this relationship with the interface provided.

I get the feeling that I've either overlooked pertinent information in the obvious places, or I haven't been looking in the right places at all. However, it's late for me, and I'm not too proud to ask for help. How do I make multiple column primary keys and foreign key references work with Class::DBI, or do I need to redesign my schema? Thank you...


In reply to Class::DBI multiple column primary and foreign keys by hangareighteen

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.