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

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Dec 10 2004 - 10:13:43 EST

  • Next message: James A. Hillyerd: "Re: How to model many-to-many relationship with self?"

    James,

    I tried your mapping in the Modeler and I don't seem to have any problems,
    regardless of whether I have "NodeMap" in the model or not. Are you having
    trouble with this panel?

    http://objectstyle.org/cayenne/images/modelerguide/objrelationship-path-selection.jpg

    One thing I noticed (this should show up as a validation message on save)
    is that node_map has no PK defined. You need to check both columns as PK
    as "childNodeMapArray" and "parentNodeMapArray" relationships as "To Dep
    PK".

    Andrus

    > 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



    This archive was generated by hypermail 2.0.0 : Fri Dec 10 2004 - 10:13:44 EST