How can I do INSERT to a dependency relation between 3 classes?

26 Views Asked by At

I have the mother class Boat and the two subclasses, sailing and motor. If it is a sail type, I have to know how many sails it has, if it is a motor, the power and if it is both a sail and a motor, all of them. The boat has the registration plate as PRIMARY KEY, so this is the FOREIGN KEY of the two subclasses. What I don't understand is how I can do the INSERTs for, depending on whether it's sail, motor or sail and motor, fill in the required information for each type.

I was thinking of doing something like:

INSERT INTO boat (registration, name)
VALUES('XXXXXXX','A');
INSERT INTO motor(registration, power)
VALUES ('XXXXXXX',35);
INSERT INTO sailing (registration, quantity)
VALUES ('XXXXXXX',3);

From what I understand, this would create a boat that is a sail and motor type. If I wanted to sail only, I would remove the motor INSERT and vice versa if I wanted it to be motor only. I'm just getting started and I don't know if this is what I need to do. Sorry if I didn't explain myself well. In theory the dependency relationship is optional and OR.

0

There are 0 best solutions below