Re: Flattened relationships example

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Sep 30 2004 - 12:56:09 EDT


Todd,

You are right - you need a join table, say "student_course". You map it
as a regular DbEntity with normal relationships to/from Course and
Student (make sure you check "To Dep PK" for "student ->
student_course" and "course -> student_course").

At the object level you only need two ObjEntities - Student and Course.
Create an ObjRelationship between them, and in the DB relationship
mapping select a chain of relationships passing through the join table.
E.g. ObjRelationship "Student.courses" will have two DbRelationships
underneath - (1) "studentCourseArray" and (2) "toCourse". Unfortunately
the docs page
(http://objectstyle.org/cayenne/modelerguide/modeling-object-layer/
flattenedrel.html) has an obsolete screenshot and "Select
DbRelationship" dialog looks differently, but it should be easy to
figure it out.

Andrus

On Sep 30, 2004, at 6:18 AM, Todd O'Bryan wrote:

> I need to do a many-to-many mapping for the first time, and I've read
> the appropriate parts of the User and Modeler guide and am still a
> little unclear about how exactly to do it.
>
> Here's what I want:
>
> I have a bunch of students and a bunch of courses. I'd like each
> student to be mapped to several (8, actually) classes, and each course
> to be mapped back to all the students that are in it. I have student
> and course dbEntities, both of which have auto-generated integer PKs.
>
> I realize I need to create a table in which a single row contains the
> student id and the course id and then use this to create a
> relationship, but I'm not clear how to do it.
>
> Could somebody walk me through it?
>
> Thanks,
> Todd
>
>



This archive was generated by hypermail 2.0.0 : Thu Sep 30 2004 - 12:56:14 EDT