in reply to Re: One to many, many to one relationships
in thread One to many, many to one relationships
Such that I can do:One-to-many: taxon ---> node ---> node ---> sequence ---> sequence One-to-one: node ---> taxon One-to-one: sequence ---> taxon
...with an underlying architecture where the relationships automatically are bi-directional in an elegant way. For example:my @nodes = $taxon->get_nodes; my @sequences = $taxon->get_sequences; my $taxon = $node->get_taxon; $taxon = $sequence->get_taxon;
...might mean that the $node now holds a reference to $taxon, but the $taxon now also has to hold a reference to $node. So should I then do:$node->set_taxon( $taxon );
...but then the $taxon->add_node( $node ) sub would likewise need to check if $node already knows about $taxon, and if not make the link in the other direction - without recursing add infinitum. All in all, that's not elegant.sub set_taxon { my ( $node, $taxon ) = @_; $node->{'_taxon'} = $taxon; # check if taxon already knows about me for my $known ( $taxon->get_nodes ) { return $node if $known == $node; } $taxon->add_node( $node ); return $node; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: One to many, many to one relationships
by agianni (Hermit) on Mar 12, 2007 at 19:24 UTC | |
by rvosa (Curate) on Mar 17, 2007 at 00:14 UTC | |
|
Re^3: One to many, many to one relationships
by lima1 (Curate) on Mar 12, 2007 at 20:43 UTC |