Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: One to many, many to one relationships

by TOD (Friar)
on Mar 12, 2007 at 04:34 UTC ( [id://604281]=note: print w/replies, xml ) Need Help??


in reply to One to many, many to one relationships

that's rather a SQL-problem than one of perl.

USE database; DROP TABLE IF EXISTS taxon; CREATE TABLE taxon (t_id INT(n) PRIMARY KEY auto_increment, [...] ); DROP TABLE IF EXISTS node; CREATE TABLE node (n_id INT(n) PRIMARY KEY auto_increment, n_t_id INT(n) NOT NULL DEFAULT 0, [...] ); DROP TABLE IF EXISTS sequence; CREATE TABLE sequence (s_id INT(n) PRIMARY KEY auto_increment, s_t_id INTn) NOT NULL DEFAULT 0, [...] );

notice that every record in the node-table, and every record in the sequence-table has to contain the pointer to a record in the taxon-table. the one-to-many relationship will then be realized by something like:
$dbh->selectall_arrayref("SELECT * FROM taxon, node WHERE n_t_id = t_i +d");

and the one-to-one realtionship you will find with a query like:
$dbh->selectrow_arrayref("SELECT * FROM node, taxon WHERE n_id = XXX A +ND t_id = n_t_id");

how you then wrap that in an object-oriented code is a matter of taste. but basically these are the things that should go on in the background.

greez
TOD

Replies are listed 'Best First'.
Re^2: One to many, many to one relationships
by lima1 (Curate) on Mar 12, 2007 at 11:01 UTC
    I had some similar task recently and found Rose::DB::Object very, very nice. See Section "Relationships" in the Tutorial.
Re^2: One to many, many to one relationships
by rvosa (Curate) on Mar 12, 2007 at 13:18 UTC
    Thanks. I agree that there's a similarity with rdbms, and elsewhere in the great big project I'm part of there's someone working on a database that models exactly these relationships in this same way, but that wasn't quite my question.
    how you then wrap that in an object-oriented code is a matter of taste.
    That was my question. I think it's not just a matter of taste, I think there are robust ways of doing this, and spaghetti-esque ways of doing it, and I can't quite figure out how to get it right. Thanks for the input, though!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://604281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found