35 lines
724 B
JavaScript
35 lines
724 B
JavaScript
|
|
module.exports = (sequelize, DataTypes) => {
|
||
|
|
const Question = sequelize.define(
|
||
|
|
"question",
|
||
|
|
{
|
||
|
|
id: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
primaryKey: true,
|
||
|
|
autoIncrement: true,
|
||
|
|
},
|
||
|
|
quizId: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: false,
|
||
|
|
references: {
|
||
|
|
model: "quiz",
|
||
|
|
key: "id",
|
||
|
|
},
|
||
|
|
},
|
||
|
|
questionText: DataTypes.STRING,
|
||
|
|
options: DataTypes.JSON,
|
||
|
|
answer: DataTypes.STRING,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
timestamps: true,
|
||
|
|
freezeTableName: true,
|
||
|
|
tableName: "question",
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
Question.associate = (models) => {
|
||
|
|
Question.belongsTo(models.quiz, { foreignKey: "quizId", as: "quiz" });
|
||
|
|
};
|
||
|
|
|
||
|
|
return Question;
|
||
|
|
};
|