๐ ์๋น์ค ํ์ค ์๊ฐ ๐
-
๊ทธ๊ฑฐ ์์? ์นญ์ฐฌ์ ํ๋ฉด ํ ์๋ก ๊ธฐ๋ถ์ด ์ข์์ง๋ค๋๊ฑฐ? ์ฐ๋ฆฌ ๋ชจ๋ ์นญ์ฐฌ ์ค๋
์ด ๋์ด๋ณด๋๊ฑฐ ์ด๋~?
-
โ ๊ณ ๋๋จ ์๋ฒ ์ปจ๋ฒค์
โ
ERD(Entity Relation Diagram)
const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require('../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.praise = require('./praise')(sequelize, Sequelize);
db.praiseTarget = require('./praiseTarget')(sequelize, Sequelize);
db.user = require('./user')(sequelize, Sequelize);
/** 1 : 1 Praise : PraiseTarget */
db.praise.hasOne(db.praiseTarget, { onDelete: 'cascade' });
db.praiseTarget.belongsTo(db.praise);
/** 1 : N User : PraiseTarget */
db.user.hasMany(db.praiseTarget, { ondDelete: 'cascade' });
db.praiseTarget.belongsTo(db.user, { onDelete: 'cascade' });
module.exports = db;