Is it possible to use a parent table Id instead of child table Id, when child table should put it's Id into another table

StackOverflow https://stackoverflow.com/questions/15929012

  •  03-04-2022
  •  | 
  •  

Pregunta

I have this Generalization relation ship between some classes in my class diagram. FirstClass as a base class that has Name attribute, SecondClass as a derived class that the FirstClass is it's base class and has some other attributes and finally ThirdClass that is a derived class from SecondClass and it has some other attributes too. ThirdClass as an association relation ship with Widget class, 1.*.

enter image description here


I used Joined strategy when I wanted to implement a Data Model from the class diagram. so the FirstTable has their Pk in the SecondTable and the SecondTable has its PK in the ThirdTable. As you see Third table should has it's PK in Widget class. And there are some costs whenever I want to Join widget table with third table because I need to fetch Name from First Table.

Is it appropriate that I read Id from FirtTable (Actually it's base class) and put it into Widget table?


¿Fue útil?

Solución

I think the problem is that if you do, you can't prevent a Widget to be related to an instance of FirstTable that is not an instance of ThirdTable.

Perhaps you could put both the ThirdTable id and the FirstTable id, but in this case you must manage security controls for consistence between both ids.

In both cases, I would advise against. If the join cost is a problem for you, you should consider using a "single table" inheritance strategy.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top