Re: how-to map reflexive relationships?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sat Oct 25 2003 - 00:49:48 EDT

  • Next message: Chumbo: "Aggregate functions - Still no luck"

    On Friday, October 24, 2003, at 04:16 PM, Rob Witt wrote:

    > How can I model a reflexive relationship so that it works in
    > Cayenne? I want to have a Document class that represents both
    > documents and folders (similar to java.io.File). I have used a
    > parentID scheme before (where a row can have many children, but only
    > one parent). I could also use a “DocumentMapping” table, whose rows
    > have a parentID and a childID that are both foreign keys to the
    > Document tables PK. Can either of these scenarios be handled by
    > Cayenne (as an official relationship)? How do I do it?

    Hi Rob,

    It should work both ways. The decision should of course depend on
    whether you have one-to-many or many-to-many relationship. E.g.
    following the filesystem paradigm (I don't know how far it applies to
    your app), on Windows it will be one parent folder per child file or
    folder; on UNIX (taking symlinks into account), you may assume that one
    folder has multiple children, and each folder or file can have one or
    more parents, so it is many-to-many.

    Incidentally I just posted a little sample app for just such a case
    (n..n) in reply to another message:

        http://objectstyle.org/cayenne/lists/cayenne-user/2003/10/0047.html

    Mapping 1..n shouldn't be hard either. You can select the same Entity
    as source and destination of the relationship... just map the keys
    accordingly.

    Hope this helps.
    Andrus



    This archive was generated by hypermail 2.0.0 : Sat Oct 25 2003 - 00:49:47 EDT