From aa23de7008cb3ec93e77491ec4682ffcfe0a1f8e Mon Sep 17 00:00:00 2001
From: Kim Siwon <shmd01@ajou.ac.kr>
Date: Sat, 16 Nov 2019 19:36:47 +0900
Subject: [PATCH 1/2] (Re) Add Diet model

---
 models/diet.js  | 33 +++++++++++++++++++++++++++++++++
 models/index.js |  1 +
 2 files changed, 34 insertions(+)
 create mode 100644 models/diet.js

diff --git a/models/diet.js b/models/diet.js
new file mode 100644
index 0000000..290961c
--- /dev/null
+++ b/models/diet.js
@@ -0,0 +1,33 @@
+module.exports = (sequelize, DataTypes) => {
+  const diet = sequelize.define('diet', {
+    photo: {
+      type: DataTypes.STRING,
+      allowNull: false,
+      validate: {
+        notNull: true,
+      },
+    },
+    memo: {
+      type: DataTypes.STRING,
+      allowNull: true,
+    },
+    feedback: {
+      type: DataTypes.STRING,
+      allowNull: true,
+    },
+  }, {
+    underscored: true,
+    timestamps: true,
+    classMethods: {},
+  });
+
+  diet.associate = (models) => {
+    diet.belongsTo(models.Trainee, {
+      foreignKey: {
+        allowNull: false,
+      },
+      onDelete: 'CASCADE',
+    });
+  };
+  return diet;
+};
diff --git a/models/index.js b/models/index.js
index 653c03a..a7f0e10 100644
--- a/models/index.js
+++ b/models/index.js
@@ -31,6 +31,7 @@ db.Trainee = require('./trainee')(sequelize, Sequelize);
 db.Program = require('./program')(sequelize, Sequelize);
 db.Voucher = require('./voucher')(sequelize, Sequelize);
 db.Inventory = require('./inventory')(sequelize, Sequelize);
+db.Inventory = require('./diet')(sequelize, Sequelize);
 
 Object.keys(db).forEach((modelName) => {
   if (db[modelName].associate) {
-- 
GitLab


From 5fa746bf80062b3c53fcfc227d6bdf0db34e81cf Mon Sep 17 00:00:00 2001
From: Kim Siwon <shmd01@ajou.ac.kr>
Date: Sat, 16 Nov 2019 19:46:59 +0900
Subject: [PATCH 2/2] Fix diet Typo

---
 models/index.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/models/index.js b/models/index.js
index a2b05fd..f971107 100644
--- a/models/index.js
+++ b/models/index.js
@@ -33,7 +33,7 @@ db.Trainee = require('./trainee')(sequelize, Sequelize);
 db.Trainer = require('./trainer')(sequelize, Sequelize);
 db.Voucher = require('./voucher')(sequelize, Sequelize);
 db.Inventory = require('./inventory')(sequelize, Sequelize);
-db.Inventory = require('./diet')(sequelize, Sequelize);
+db.Diet = require('./diet')(sequelize, Sequelize);
 
 Object.keys(db).forEach((modelName) => {
   if (db[modelName].associate) {
-- 
GitLab