Single inheritance or polymorphic?

I am programming a website that allows users to post ads with detailed fields for the different types of products they sell. However, I have a question about the best database schema.

There are many categories on the site (for example, cars, computers, cameras), and each category of ads has its own fields. For example, cars have attributes such as the number of doors, make, model and horsepower, while computers have attributes such as processor, RAM, motherboard model, etc.

Now, since they are all lists, I was thinking of a polymorphic approach, creating a parent LISTINGS table and another child table for each of the different categories (COMPUTERS, CARS, CAMERAS). Each child table will have a listing_id that will reference a LISTINGS TABLE table. Therefore, when a list is set, it will retrieve a row from LISTINGS joined by a linked row in the linked child table.

LISTINGS
-listing_id
-user_id
-email_address
-date_created
-description

CARS
-car_id
-listing_id
-make
-model
-num_doors
-horsepower

COMPUTERS
-computer_id
-listing_id
-cpu
-ram
-motherboard_model

So, is this design a good design pattern or are there any better ways to do this?

, , , - , , . , 100 , ?

, (-), , , ?

, ?

+3
2

. , . , . , , , . , , , , , , . .

, .

.

- -

CategoriesListingsXref - CategoryId - ListingId

. sql ( ) , (), , .

.

2 , , , . , , , .       http://www.sommarskog.se/dyn-search-2008.html

. .

+2

, , , , . , . CAR , , "".

, . , , , . , "" . , , (RAM > 4gb, cpu = overpowered).

0

Source: https://habr.com/ru/post/1779479/


All Articles