Re: Question about flatten relationship

From: Craig Miskell (cmiskel..lbatross.co.nz)
Date: Fri Nov 22 2002 - 21:23:26 EST

  • Next message: Craig Miskell: "Re: [Ask]how to run cayenne-1.0b1-dev JUnit test"

    Hi,
            In the case that the relationship is across a many-to-many link
    table that consists solely of the foreign keys of the relationships, then
    Cayenne will indeed take care of things, and the relationship is
    writable. Cayenne only sets the relationship to readonly if it's
    flattened and *not* as described above.

    In your example, I'm assuming that Student has a pk (say, student_id),
    Course has a pk (say, course_id), and that there is a link table
    StudentCourseLink which has student_id and course_id in it (and only those
    attributes).

    In this case, addToCourses should "just work". If it's not, then there's
    a bug that needs to be worked out. If it looks like a bug, send me your
    Data map xml files and I'll see if there's anything in those that is out
    of place. For example, any additional attributes in StudentCourseLink
    will be enough for Cayenne to make the relationship "read-only".

    Craig

     On Fri, 22 Nov 2002, xuzhou wrote:

    > Hi all,
    >
    > The following italic text is excerpted from Release Notes of Cayenne 1.0b1. I think this feature is very useful, but I hava a question about it. Why the flattened relationship is readonly?
    >
    > Suppose the many-to-many relationship between student and course. The DataObject, Student, would have method addToCourses(Course obj). But this mothod can not be called to avoid CayenneRuntimeException is thrown. I think if this method can be called, i.e.,the flatten relationship is writable, the DataObject could be operated more convenient.
    >
    >
    > 8. Added support for flattened relationships. Modeller now suggests all available
    > paths from the source entity to the destination entity for selection. For simple flattened
    > relationships that span a many-many link table consisting solely of fk's to the linked rows,
    > cayenne will automatically add/remove the link records. In that case, there is no need to
    > have an ObjEntity for the link record, and this is in fact discouraged. All other flattened
    > relationships are set "readOnly" and cannot be modified.
    >
    >
    > Regards,
    >



    This archive was generated by hypermail 2.0.0 : Fri Nov 22 2002 - 21:23:51 EST