-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.js
49 lines (44 loc) · 1004 Bytes
/
models.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { Sequelize, Model, DataTypes } = require("sequelize");
const path = require("path");
const sequelize =
process.env.NODE_ENV === "test"
? new Sequelize("sqlite::memory:", null, null, { dialect: "sqlite" })
: new Sequelize({
dialect: "sqlite",
storage: path.join(__dirname, "data.db"),
});
class Restaurant extends Model {}
Restaurant.init(
{
name: DataTypes.STRING,
image: DataTypes.STRING,
},
{ sequelize, modelName: "restausrant" }
);
class Menu extends Model {}
Menu.init(
{
title: DataTypes.STRING,
image: DataTypes.STRING,
},
{ sequelize, modelName: "menu" }
);
class Item extends Model {}
Item.init(
{
name: DataTypes.STRING,
price: DataTypes.FLOAT,
image: DataTypes.STRING,
},
{ sequelize, modelName: "item" }
);
Restaurant.hasMany(Menu, { as: "menus" });
Menu.belongsTo(Restaurant);
Menu.hasMany(Item, { as: "items" });
Item.belongsTo(Menu);
module.exports = {
Restaurant,
Menu,
Item,
sequelize,
};