Menu

Attribute associated with 2 classes by type

2004-10-27
2013-03-07
  • Marcos Flavio de Oliveira

    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?

     
    • Richard Banks

      Richard Banks - 2004-10-27

      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.

       
      • Marcos Flavio de Oliveira

        Thanks Richard!
        I'm trying it and inform you after.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.