0

Hi guys,
I have 3 classes : 1.Product(Super Class) 2.SmartDevice(Sub Class) 3.Accessories(Sub Class)

so I made 3 tables in database and made productId as a foreign key for smartDevice table and accessories table

so I've had a trouble thinking about what the code of CRUD will be if I used the generalization I mentioned above

Example:
I want to add a function to insert a product into database in the class of product

I Left 2 attachments to explain my condition:

71b1ae6c75814548b76a0cb671b1dd94

233e4d4d451511809150b34805e2be0f

Edited by safi.najjar1: I made a mistake

2
Contributors
2
Replies
25
Views
3 Years
Discussion Span
Last Post by safi.najjar1
1

If I understand your question you want to insert a product into the products table and then, depending on whether it is an accessory or a smart device, also insert into the relevant secondary table.
So your secondary, subclass tables will have a productId column that matches the productId in the products table.
Insert a product into the products table and return the inserted productId. Use that id to do the insert into the secondary table. You now have a link between the two.
You can also add a foreign key constraint from accessories/smart devices to products with on delete cascade to keep your table integrity intact.
is that any help?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.