]>
Commit | Line | Data |
---|---|---|
67bf9b96 C |
1 | 'use strict' |
2 | ||
3 | const customUsersValidators = require('../helpers/custom-validators').users | |
4 | ||
feb4bdfd C |
5 | module.exports = function (sequelize, DataTypes) { |
6 | const Author = sequelize.define('Author', | |
7 | { | |
8 | name: { | |
67bf9b96 C |
9 | type: DataTypes.STRING, |
10 | allowNull: false, | |
11 | validate: { | |
12 | usernameValid: function (value) { | |
13 | const res = customUsersValidators.isUserUsernameValid(value) | |
14 | if (res === false) throw new Error('Username is not valid.') | |
15 | } | |
16 | } | |
feb4bdfd C |
17 | } |
18 | }, | |
19 | { | |
20 | classMethods: { | |
21 | associate | |
22 | } | |
23 | } | |
24 | ) | |
25 | ||
26 | return Author | |
27 | } | |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
31 | function associate (models) { | |
32 | this.belongsTo(models.Pod, { | |
33 | foreignKey: { | |
34 | name: 'podId', | |
35 | allowNull: true | |
36 | }, | |
37 | onDelete: 'cascade' | |
38 | }) | |
39 | } |