Is SQL inheritance still required when implementing composition?

Describe what you’ve built or ask your questions in enough detail, so others can clearly understand and (hopefully) replicate! Screenshots and lI will be using PHP and SQL to create either a gas, diesel, or electric car.

One option is to use class type inheritance and then create some classes, but doing so often goes down a dead end.

AbstractCar
-id
-discriminator
-commonAttributesToAllCars

GasCar extends AbstractCar
-id, uniqueAttributes, etc
DieselCar extends AbstractCar
-id, uniqueAttributes, etc
ElectricCar extends AbstractCar
-id, uniqueAttributes, etc
Instead, I will be using composition, and restructured my DB as follows:

Car
-id
-commonAttributesToAllCars
-engineId

Engine
-id
-engineAttributes
But now I discover that different gas, diesel, and electric engines require different attributes.

I feel better about using class type inheritance for engines than cars because the entities are smaller and simpler, however, would still rather not if there is a better way.

Car
-id
-commonAttributesToAllCars
-abstractEngineId

AbstractEngine
-id
-discriminator
-commonAttributesToAllEngines

GasEngine extends AbstractEngine
-id, uniqueAttributes, etc
DieselEngine extends AbstractEngine
-id, uniqueAttributes, etc
ElectricEngine extends AbstractEngine
-id, uniqueAttributes, etc
How should this be implemented without using any inheritance?inks to what you built are encouraged.

Hi, @vivan!

Welcome to the Knack community! :wave:

It seems as though you are looking for guidance on using custom JS for your Knack app. We have a category in our forum here to ask other fellow developers these types of questions and posting this there may increase your chances of a developer replying: Ask Developers - Knack Community Forum

While I’m unable to provide any suggestions with custom code, please feel free to check out our Knack Expert Network if you would like to hire an expert to help you with your project: Knack Experts Network

Happy building! :rocket:

1 Like