-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment.js
49 lines (46 loc) · 896 Bytes
/
Comment.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 { Model, DataTypes } = require('sequelize')
const sequelize = require('../config/connection')
class Comment extends Model {}
Comment.init(
{
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
comment_text: {
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [1],
},
},
created_on: {
type: DataTypes.DATEONLY,
allowNull: false,
defaultValue: DataTypes.NOW,
},
user_id: {
type: DataTypes.INTEGER,
references: {
model: 'user',
key: 'id',
},
},
post_id: {
type: DataTypes.INTEGER,
references: {
model: 'post',
key: 'id',
},
},
},
{
sequelize,
freezeTableName: true,
underscored: true,
modelName: 'comment',
}
)
module.exports = Comment