by Michael Patricks >> Wed, 18 Aug 2004 3:44:15 GMT
Hi
I am creating references for two objects that are essentially related in a many-many relationship.
However, the relationship between the two objects also includes some attributes. So to solve this problem I have created an intermediary object. E.g:
ThisObject and ThatObject are the two main objects. They are related to each other through an other Object, MiddleObject.
The MiddleObject then has a reference to each of the two main objects, myThisObject and myThatObject. The two main objects then have a inverse collection on each called allMiddleObjects.
My problem is: Have i implemented this correctly? MiddleObjects should never exists without valid references to both the main objects ThisObject and ThatObject. I have implemented the inverses as having the collection as the manual side and the straight reference as the automatic. I thought this would ensure that programmatically it would be hard for the MiddleObjects to be manipulated to the point that they no longer to belonged to either one or both of the main objects. The deletion of the main Objects is also handled so that all the related MiddleObjects are removed from both collections of the ThisObject and ThatObject then deleted.
As for the key attribute of the MiddleObject, there is no defining identifier for them (it holds three decimal fields for currency values) so i thought i would either have an arbitrary attribute made up of both the key attributes on the main Objects or have two attributes which hold the actual values of the main Objects' key attributes themselves.
Is there a better way to do this?
Cheers
Mike