diff options
Diffstat (limited to 'server/models/video/video-share.ts')
-rw-r--r-- | server/models/video/video-share.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts new file mode 100644 index 000000000..358491fd2 --- /dev/null +++ b/server/models/video/video-share.ts | |||
@@ -0,0 +1,49 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | import { addMethodsToModel } from '../utils' | ||
4 | import { VideoShareAttributes, VideoShareInstance } from './video-share-interface' | ||
5 | |||
6 | let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes> | ||
7 | |||
8 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | ||
9 | VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare', | ||
10 | { }, | ||
11 | { | ||
12 | indexes: [ | ||
13 | { | ||
14 | fields: [ 'accountId' ] | ||
15 | }, | ||
16 | { | ||
17 | fields: [ 'videoId' ] | ||
18 | } | ||
19 | ] | ||
20 | } | ||
21 | ) | ||
22 | |||
23 | const classMethods = [ | ||
24 | associate | ||
25 | ] | ||
26 | addMethodsToModel(VideoShare, classMethods) | ||
27 | |||
28 | return VideoShare | ||
29 | } | ||
30 | |||
31 | // ------------------------------ METHODS ------------------------------ | ||
32 | |||
33 | function associate (models) { | ||
34 | VideoShare.belongsTo(models.Account, { | ||
35 | foreignKey: { | ||
36 | name: 'accountId', | ||
37 | allowNull: false | ||
38 | }, | ||
39 | onDelete: 'cascade' | ||
40 | }) | ||
41 | |||
42 | VideoShare.belongsTo(models.Video, { | ||
43 | foreignKey: { | ||
44 | name: 'videoId', | ||
45 | allowNull: true | ||
46 | }, | ||
47 | onDelete: 'cascade' | ||
48 | }) | ||
49 | } | ||