Built motion from commit 95b01fa.|0.0.70
[motion.git] / server / models / report_jscripty_question.js
1 'use strict';
2
3 module.exports = function(sequelize, DataTypes) {
4   return sequelize.define('ReportJscriptyQuestion', {
5     question_id: DataTypes.INTEGER,
6     question_type: DataTypes.STRING,
7     question_label: DataTypes.STRING,
8     question_text: DataTypes.STRING,
9     question_answer: DataTypes.STRING,
10     question_other_label: DataTypes.STRING,
11     question_other_answer: DataTypes.STRING
12
13   }, {
14     tableName: 'report_jscripty_questions',
15     associate: function(models) {
16       models.ReportJscriptyQuestion.hasMany(models.ReportJscriptyInput, {
17         onDelete: 'cascade',
18         foreignKey: 'questionId'
19
20       });
21       models.ReportJscriptyQuestion.addScope('questionSummary', function(projectId) {
22         return {
23           where: {
24             projectId: projectId
25
26           },
27           attributes: ['question_id', 'question_type', 'question_label', 'question_text', [sequelize.fn('count', sequelize.col('question_id')), 'count']],
28           group: ['question_id', 'question_type', 'question_label', 'question_text']
29         }
30
31       });
32     }
33   });
34 };