Can both Student and Course have Enrollment collections?
Can Enrollment have a reference back to both Student and Course? 
Would Enrollment depend on Student or Course or neither?
 
Right now I am trying a 3 way many-to-many, and that doesn't feel right.
 
Thanks!
jwc
-----Original Message-----
From: Ralf Joachim [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 23, 2003 2:14 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Many-to-Many with an association object

Hello John,
 
castor do not support many-to-many relations with additional properties in the association.
 
That means for your example, if you use many-to-many relation between Student and Course  with Enrollment as association, Enrollment can not have grade or days missed.
 
If you want Enrollment to have grade and days missed you have to view Enrollment not as association object but as a standalone object and use a one-to-many relations between Student and Enrollment and also between Course and Enrollment and get the result you want.
 
Regards
Ralf
----- Original Message -----
Sent: Tuesday, December 23, 2003 6:53 PM
Subject: [castor-dev] Many-to-Many with an association object

I've run into a small problem with many-to-many relationships, and I am not sure what to put in the mapping.xml. Here is my admittedly contrived example. I will try to come up with a working test for this, if necessary. Hopefully, this is going to be one of those "Why are you trying to do it the hard way! Try this easier way" type of things.
 
Object side:
Student and Course have a many-to-many relationship. This relationship is realized by an Enrollment association object. The Enrollment object will have things in it like the grade and number of days missed.
 
Database side:
Student table and Course table, with an association table called Enrollment, which has a column for the course id, a column for the student id, and columns for both the grade and the number of days missed.
 
Now, all of the examples that I have seen with Castor and many to many relationships show an association table like Enrollment, but with no extra columns. Also, all of the examples don't make an object out of Enrollment. Student would have a collection of Courses and Courses would have a collection of Students.
 
What can I put into the mapping file so that I can have my Student object get a collection of Enrollment objects. Student does not need to have a collection of Course objects. I can make that up on the fly by going through the collection of Enrollment objects.
 
Also, when the Student goes away, the Enrollments have to go away, and, likewise, when the Course goes away, the Enrollments have to go away. The removal of Student should not directly affect Course, and the removal of Course should not directly affect Student. (Indirectly they would be affected by the removal of the associated Enrollment).
 
Can I do the Enrollment object the way I have described? If not, what would be the right way to do this?
 
Many thanks!
jwc

Reply via email to