I have a class A with attribute X (Oid) and Y (Oid). The attribute X can reference a class B or C depends off attribute Y (type). How I can implements it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you wanting to autoretrieve the association to B/C or do you want to do it in code?
To just throw an idea out there...
If you want to do it in the mapping, I suppose you could try creating two autoretrieve associations (A-B, A-C) both using X as the fromAttribute. When you retrieve A, the SQL will try to join to both B and C, but only one object will actually be instantiated, since only the columns for B or C will have non-null values.
Your class could then have a readonly property that returns either B or C depending on Y's value to make referencing the B/C objects transparent.
Just an idea, it may work - it may not. You can always try it and see ;-)
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dears,
I have a class A with attribute X (Oid) and Y (Oid). The attribute X can reference a class B or C depends off attribute Y (type). How I can implements it?
Hi Marcos,
Good question :-)
Are you wanting to autoretrieve the association to B/C or do you want to do it in code?
To just throw an idea out there...
If you want to do it in the mapping, I suppose you could try creating two autoretrieve associations (A-B, A-C) both using X as the fromAttribute. When you retrieve A, the SQL will try to join to both B and C, but only one object will actually be instantiated, since only the columns for B or C will have non-null values.
Your class could then have a readonly property that returns either B or C depending on Y's value to make referencing the B/C objects transparent.
Just an idea, it may work - it may not. You can always try it and see ;-)
- Richard.
Thanks Richard!
I'm trying it and inform you after.