-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathquestions.js
33 lines (33 loc) · 906 Bytes
/
questions.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
'use strict';
module.exports = (sequelize, DataTypes) => {
var questions = sequelize.define('questions', {
title: {
type: DataTypes.STRING,
allowNull: false
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
difficulty: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
correctAnswers: {
type: DataTypes.ARRAY(DataTypes.BIGINT),
allowNull: false,
defaultValue: []
}
}, {
paranoid: true
});
questions.associate = function(models) {
questions.belongsTo(models.users, {foreignKey: 'createdById'})
questions.hasMany(models.choices)
questions.belongsTo(models.users,{foreignKey: 'updatedById'})
questions.belongsToMany(models.quizzes, {through: models.quizQuestions})
questions.belongsToMany(models.tags, {through: models.question_tags})
};
return questions;
};