----- 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