AS A manager at an internet retail company
I WANT a back end for my e-commerce website that uses the latest technologies
SO THAT my company can compete with other e-commerce companies
Your database should contain the following four models, including the requirements listed for each model:
-
Category
-
id
-
Integer.
-
Doesn't allow null values.
-
Set as primary key.
-
Uses auto increment.
-
-
category_name
-
String.
-
Doesn't allow null values.
-
-
-
Product
-
id
-
Integer.
-
Doesn't allow null values.
-
Set as primary key.
-
Uses auto increment.
-
-
product_name
-
String.
-
Doesn't allow null values.
-
-
price
-
Decimal.
-
Doesn't allow null values.
-
Validates that the value is a decimal.
-
-
stock
-
Integer.
-
Doesn't allow null values.
-
Set a default value of
10
. -
Validates that the value is numeric.
-
-
category_id
-
Integer.
-
References the
Category
model'sid
.
-
-
-
Tag
-
id
-
Integer.
-
Doesn't allow null values.
-
Set as primary key.
-
Uses auto increment.
-
-
tag_name
- String.
-
-
ProductTag
-
id
-
Integer.
-
Doesn't allow null values.
-
Set as primary key.
-
Uses auto increment.
-
-
product_id
-
Integer.
-
References the
Product
model'sid
.
-
-
tag_id
-
Integer.
-
References the
Tag
model'sid
.
-
-
You'll need to execute association methods on your Sequelize models to create the following relationships between them:
-
Product
belongs toCategory
, andCategory
has manyProduct
models, as a category can have multiple products but a product can only belong to one category. -
Product
belongs to manyTag
models, andTag
belongs to manyProduct
models. Allow products to have multiple tags and tags to have many products by using theProductTag
through model.