Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: One to many, many to one relationships

by graff (Chancellor)
on Mar 12, 2007 at 04:44 UTC ( [id://604283]=note: print w/replies, xml ) Need Help??


in reply to One to many, many to one relationships

I think the question hinges on when the linkage information first becomes available: is it instrinsically known at the point when an object instance is created, or might it get introduced at some later stage as an update to an existing instance?

If it makes sense that instances of each object type are able to exist independently, without necessarily being linked to one of the other object types, then it would make sense for link creation to be a separate process, which takes a taxon instance and a node or sequence instance, and updates each one by adding a reference to the other. (In the taxon, a reference to a node or sequence would be pushed onto an array of nodes or sequences; in a node or sequence, there can be only one reference to a given taxon.)

OTOH, if every node and/or every sequence being created is inherently related to a specific taxon, then it would make sense that the "new()" method for node and sequence objects would take a required reference to a taxon instance, check to make sure this reference is defined, create the new node or sequence instance that contains the reference to that taxon, and finally invokes the "add_node" or "add_sequence" method of that taxon, to make the relation bidirectional.

(At least one of the object types needs to be able to exist independently, without requiring a relation to the other types. It sounds like the taxon object would be that way for sure.)

(update: And I agree with TOD, that it makes more sense if the underlying data storage is a relational database, where foreign key relations can be enforced automatically once you define the tables properly, rather than just being a bunch of perl-internal objects.)

  • Comment on Re: One to many, many to one relationships

Replies are listed 'Best First'.
Re^2: One to many, many to one relationships
by rvosa (Curate) on Mar 12, 2007 at 13:26 UTC
    I think the question hinges on when the linkage information first becomes available: is it instrinsically known at the point when an object instance is created, or might it get introduced at some later stage as an update to an existing instance?
    It might be introduced later - especially for nodes, which might never be linked to a taxon.

    Also, I don't want to/can't change the api such that the link has to be created in the constructor.
    If it makes sense that instances of each object type are able to exist independently, without necessarily being linked to one of the other object types, then it would make sense for link creation to be a separate process, which takes a taxon instance and a node or sequence instance, and updates each one by adding a reference to the other. (In the taxon, a reference to a node or sequence would be pushed onto an array of nodes or sequences; in a node or sequence, there can be only one reference to a given taxon.)
    Yup, that's what I tend towards. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found