I have already seen a mapping example of recursive relationship that uses a foreign key on the same table. As for my case, the recursive relationship is using a cross-reference table to resolve many-to-may relationship. The following should illustrate the DB structure.
Basically, a part has a list of substitute parts. Conversely, a part can also be a substitute of several primary parts.
From a class perspective, I would assume that they can just use the same class named
Part. Only that if it's a primary part, it will have a list of substitute parts and if it's a substitute part, it will have a linkage to its primary parts.
My question is:
How can I map the substitute parts in the
Part class so that it uses the same class as part? Is this possible in the first place? Take note that the primary part would have to query the
PART_SUBSTITUTE_XREF table first and get the substitute part numbers before querying back to the
PART table and use those part numbers to get the details of the substitute parts.
The following SQL statement should illustrate what I want to happen.
Code:
select substitute.*
from PART part
left outer join PART_SUBSTITUTE_XREF xref on part.part_no = xref.part_no
left outer join PART substitute on substitute.part_no = xref.sub_part_no
where part.part_no = 798