Re: How to model many-to-many relationship with self?

From: Jürgen Saar (jsaa..eb.de)
Date: Fri Dec 10 2004 - 01:31:49 EST

  • Next message: Andrus Adamchik: "RE: Setting objects across datanodes"

    First I have a question:

    Are you sure that it has to be many-to-many ?

    If you have a tree-structure
    parent --> child is 1-to-many
    and
    child --> parent is 1-to-1

    Second question:

    what flattened relationships do you need?
    Grandchild?
    Grandparent?

    "James A. Hillyerd" <jame..illyerd.com> schrieb am 10.12.04 00:12:54:
    >
    > Hi, I'm new to Cayenne. I have a question about many-to-many
    > relationships, specifically how to relate an object back to it's own type.
    >
    > I want to have a model of generic "Node" objects, each which can have
    > 0-many children (and implicitly 0-many parents).
    >
    > Here is a sample database schema definition (for PostgreSQL, but should
    > be pretty generic):
    >
    > create table node (
    > node_id bigint not null,
    > name varchar(40) not null,
    > primary key (node_id)
    > );
    >
    > create table node_map (
    > parent_node_id bigint not null,
    > child_node_id bigint not null
    > );
    >
    > alter table node_map
    > add constraint node_map_parent_fk foreign key (parent_node_id)
    > references node (node_id);
    >
    > alter table node_map
    > add constraint node_map_child_fk foreign key (child_node_id)
    > references node (node_id);
    >
    >
    > After reverse engineering this schema I played around with the modeler
    > some, and was having a lot of trouble "flattening" the relationship.
    > Things are really confusing since everything is a Node! It seems like
    > things snap into place when I delete the "NodeMap" object entity - did I
    > have to do that first?
    >
    > I'm attaching my project/map files, maybe someone could take a look at
    > them and tell me if I did things right? Also will Cayenne be able to
    > keep both the child and parent arrays in sync, or do I need to have just
    > a child array?
    >
    > One more question... what is the Data View modeler for?
    >
    > Thanks!
    >
    > -james
    >
    > --
    > James A. Hillyerd <jame..illyerd.com>
    > Java Software Engineer - ActiveRain.com
    >
    __________________________________________________________
    Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
    weltweit telefonieren! http://freephone.web.de/?mc=021201



    This archive was generated by hypermail 2.0.0 : Fri Dec 10 2004 - 01:32:01 EST