Re: Many to Many Relation

From: Dhruti Ramani (dhrutiraman..ahoo.com)
Date: Wed Jun 29 2005 - 14:11:53 EDT

  • Next message: Mike Kienenberger: "Re: Many to Many Relation"

    Thanks for helping. I have tried what ever you asked in your last email. I have created a new DbEntity called "UserRole_systemUser" and between UserRole and UserRole_systemUser I did 1 to M and between UserRole_SystemUser and SystemUser I have 1 to 1. is this correct?
     
    now in object entity I can get ToMany relation from "UserRole" but not from "SystemUser".
     
    What am I missing here?
    Thanks,
    Denna

    Mike Kienenberger <mkienen..laska.net> wrote:
    Dhruti Ramani wrote:
    > In my object model I have two objects UserRole and SystemUser. I need to
    have Many to Many relation between them. UserRole can have any no. of
    systemUsers and SystemUser can have many roles. I have added a foreign
    key(userRole1_id) in UserRole and systemUser_id is the primary key for
    SystemUser. Here is what I have tried.....
    >
    > Relation From To Join
    > users UserRole SystemUser (userRole1_id ---
    systemUser_id) ("to_dep_key checked)
    > roles SystemUser UserRole
    (systemUser_id----userRole1_id)
    >
    > But when I create those two objects and try to add user to userRole or
    userRole to user, it does not persist in the database. Individually both
    objects are there in the database but there is no relation between them and
    I don't get any errors.

    Yes, this is well-supported in Cayenne and is called a flattened
    relationship. Check the user guide for full details, but in generaly,
    here's what you'll need to do:

    Make sure you have DbEntities for USER_ROLE, SYSTEM_USER, and
    SYSTEM_USER_ROLE (or whatever your join table is called).

    Set up relationships between USER_ROLE and SYSTEM_USER_ROLE and
    relationships between SYSTEM_USER and SYSTEM_USER_ROLE.

    Note that the "to_dep_key" must be set on the USER_ROLE and in SYSTEM_USER
    DbRelationships rather than in SYSTEM_USER_ROLE relationships.

    After you've done this, you will only need ObjEntities for UserRole and
    SystemUser.

    You should be able to set up a to-many relationship directly between
    USER_ROLE and SYSTEM_USER, and it should automatically pick up the two-step
    join from the DbRelationships. (ie, USER_ROLE.USER_ROLE_ID ->
    SYSTEM_USER_ROLE.USER_ROLE_ID and SYSTEM_USER_ROLE.SYSTEM_USER_ID ->
    SYSTEM_USER.SYSTEM_USER_ID.)

    -Mike

                    
    ---------------------------------
    Yahoo! Mail
     Stay connected, organized, and protected. Take the tour



    This archive was generated by hypermail 2.0.0 : Wed Jun 29 2005 - 14:11:54 EDT