Built motion from commit d415888.|0.0.73
[motion.git] / server / models / analytics_custom_report.js
1 'use strict';
2
3 module.exports = function(sequelize, DataTypes) {
4
5   var CustomReport = sequelize.define('CustomReport', {
6     name: DataTypes.STRING,
7     description: DataTypes.STRING,
8     parent: DataTypes.STRING,
9     table: DataTypes.STRING,
10     conditions: DataTypes.TEXT
11   }, {
12     paranoid: true,
13     tableName: 'analytics_custom_reports',
14     associate: function(models) {
15       CustomReport.hasMany(models.ReportField, {
16         as: 'Fields',
17         onDelete: 'cascade',
18         hooks: true
19       });
20       CustomReport.addScope('fields', {
21         include: [{
22           model: models.ReportField,
23           as: 'Fields',
24           required: false,
25           attributes: ['field', 'alias', 'function', 'groupBy', 'orderBy', 'MetricId']
26         }]
27       });
28     }
29   });
30
31   return CustomReport;
32 };