cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Becker <>
Subject Best way to create many-to-many relationship in Cayenne Modeller
Date Thu, 25 Aug 2011 19:24:29 GMT
I think I finally understand how I can create a many-to-many relationship
between objects in the modeler, but there are a lot of steps and some seem a
bit repetitive, so I want to ask if this is really the best / most
convenient way of doing it. In my example, I have Users and Exercises: users
perform a number of exercises, and exercises are performed by a number of
users, so we have a many to many. I would like to be able to just go to the
User object and add a many-to-many relation to Exercise, but as far as I can
tell i actually have to perform these steps (please correct me if I'm wrong;
i worked through these steps as I typed this so I know this at least works):

* Create a join table USER_EXERCISE to join the User pk and Exercise pk
    * Create user_id and exercise_id attributes
    * In the USER_EXERCISE table, create a to-one relationship to the User
pk, and a to-one relationship to the Exercise pk:
        * Select the USER_EXERCISE entity
        * Select the Relationships tab
        * Click the Create Relationship button
        * Name it "exerciseUsers"
        * Select the Target to be the USER table
        * Click the inspector button (first change focuse from Target
dropdown so that the inspector button is enabled)
        * In the DbRelationship Info dialog:
    * Name the Relationship "userExercises" and the Reverse Relationship
            * Add a join by clicking the Add button
            * For Source select exercise_id, and for Target select id (pk
from EXERCISE table)
    * Repeate the same steps for the relation to the Exercise pk, naming the
relationship "userExercises"
* Create a flattened many-to-many relationship in the User object
* Select the User object (not the table)
* Go to the Relationships tab
* Click Create Relationship
* Click the Edit Relationship button. In the ObjRelationship Inspector
dialog that opens:
* Name the relationship "exercises"
* for Target select Exercise
* Under "Mapping to DbRelationships" section, select "exercises"
relationship, then the "userExercises" relationship (from the join table)
* Click "Select Path"
* Click "Done"
* Create a flattened many-to-many relationship in the Exercise object using
the same steps

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message