]>
Commit | Line | Data |
---|---|---|
7920c273 C |
1 | 'use strict' |
2 | ||
3 | // --------------------------------------------------------------------------- | |
4 | ||
5 | module.exports = function (sequelize, DataTypes) { | |
6 | const Tag = sequelize.define('Tag', | |
7 | { | |
8 | name: { | |
67bf9b96 C |
9 | type: DataTypes.STRING, |
10 | allowNull: false | |
7920c273 C |
11 | } |
12 | }, | |
13 | { | |
319d072e C |
14 | timestamps: false, |
15 | indexes: [ | |
16 | { | |
17 | fields: [ 'name' ], | |
18 | unique: true | |
19 | } | |
20 | ], | |
7920c273 C |
21 | classMethods: { |
22 | associate | |
23 | } | |
24 | } | |
25 | ) | |
26 | ||
27 | return Tag | |
28 | } | |
29 | ||
30 | // --------------------------------------------------------------------------- | |
31 | ||
32 | function associate (models) { | |
33 | this.belongsToMany(models.Video, { | |
34 | foreignKey: 'tagId', | |
35 | through: models.VideoTag, | |
36 | onDelete: 'cascade' | |
37 | }) | |
38 | } |