Perhaps the question wasn't posed properely. Any help on this would be fantastic and much appreciated - I'm tearing my hair out.
He's another example:
I have Student and Course Classes. with a many to many relationship.
Student Class:
Code:
<class name="Student" table="student">
<id name="StudentId" type="Decimal">
<column name="STUDENT_ID"/>
</id>
<property name="Name" type="String">
<column name="NAME" length="100" not-null="true"/>
</property>
<property name="Deleted" type="Decimal">
<column name="DELETED" not-null="true"/>
</property>
<idbag name="Courses" inverse="true" table="StudentCourses">
<collection-id column="STUDENT_COURSE_ID" type="Decimal">
</collection-id>
<key>
<column name="STUDENT_ID" not-null="true"/>
</key>
<many-to-many class="Course" column="COURSE_ID" />
</idbag>
</class>
Course Class:
Code:
<class name="Course" table="course">
<id name="CourseId" type="Decimal">
<column name="COURSE_ID"/>
</id>
<property name="Name" type="String">
<column name="NAME" length="100" not-null="true"/>
</property>
<property name="Deleted" type="Decimal">
<column name="DELETED" not-null="true"/>
</property>
<idbag name="Students" inverse="false" table="StudentCourses">
<collection-id column="STUDENT_COURSE_ID" type="Decimal">
</collection-id>
<key>
<column name="COURSE_ID" not-null="true"/>
</key>
<many-to-many class="Student" column="STUDENT_ID" />
</idbag>
</class>
This is all well and good. Now I want to only see non deleted courses or students when I traverse the from Student.Courses or Course.Students
I can do this simply by adding where="DELETED=0" to the many-to-many tags and viola!
in the Course Mapping:
Code:
...
<many-to-many class="Student" column="STUDENT_ID" where="DELETED=0" />
...
and in the Student Mapping:
Code:
...
<many-to-many class="Course" column="COURSE_ID" where="DELETED=0" />
...
Now I want to throw another twist in the mix. Let's say I want to add another column to the StudentCourse table and seperate it into it's own class:
Code:
<class name="StudentCourse" table="student_course">
<id name="StudentCourseId" type="Decimal">
<column name="STUDENT_COURSE_ID"/>
</id>
<property name="SomeProperty" type="String">
<column name="SOMEPROPERTY" length="100" not-null="true"/>
</property>
<many-to-one name="Course" class="Course">
<column name="COURSE_ID" />
</many-to-one>
<many-to-one name="Student" class="Student">
<column name="STUDENT_ID" />
</many-to-one>
</class>
now that I have this defined I'll update the mappings of the Student to change the collection to a one-to-many to StudentCourse instead of a many-to-many to Course:
Code:
...
<bag name="StudentCourses">
<key>
<column name="STUDENT_ID" not-null="true"/>
</key>
<one-to-many class="StudentCourse" />
</bag>
...
and do the same from Courses to StudentCourse:
Code:
...
<bag name="StudentCourses">
<key>
<column name="COURSE_ID" not-null="true"/>
</key>
<one-to-many class="StudentCourse" />
</bag>
...
Now for the main question:
what can I do to only see students and courses that have a deleted property=0 (not deleted)
It was easy when it was a direct many-to-many by using the where="DELETED=0" attribute on the many-to-many tags.
What can I do when using this intermediary StudentCourse class as the go-between?
It seems like many people should have run into this scenario before. I was wondering what the solution is.
Any help would be GREATLY appreciated..
Thanks[/code]