I have 3 tables:
Plane (ID, Name) //Parent
Car(ID, Name) //Parent
Engine(ID, Name) //Child
Engine
table must have a parent which is either Plane
or Car
. These tables are related with 1-to-1 relationship.
The main thing is that there is a need to get a parent through engine. How to correctly setup a database here?
I see multiple scenarios here but cannot figure out which is the best one:
- Put
engine ID
atPlane
andCar
. The problem I am facing here is that before I query I need to know which parent engine belongs to. - Have
plane_engine
andcar_engine
tables. Same problem as above + more overhead with separate tables which are more required for many-to-many relationship (which is not a case here) - Have a soft key and type at engine table (Parent_ID, Type). Problem which is at 1 and 2 scenarios is reduced but I cannot ensure that Type and Parent_ID will be true and represent what it should (f.e. Type is Car but Parent ID is of plane).
Any insights would be great. Thank you!