Remove references to author
[oweals/peertube.git] / server / models / account / account-follow.ts
1 import * as Sequelize from 'sequelize'
2
3 import { addMethodsToModel } from '../utils'
4 import {
5   AccountFollowInstance,
6   AccountFollowAttributes,
7
8   AccountFollowMethods
9 } from './account-follow-interface'
10
11 let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes>
12
13 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
14   AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
15     { },
16     {
17       indexes: [
18         {
19           fields: [ 'accountId' ],
20           unique: true
21         },
22         {
23           fields: [ 'targetAccountId' ],
24           unique: true
25         }
26       ]
27     }
28   )
29
30   const classMethods = [
31     associate
32   ]
33   addMethodsToModel(AccountFollow, classMethods)
34
35   return AccountFollow
36 }
37
38 // ------------------------------ STATICS ------------------------------
39
40 function associate (models) {
41   AccountFollow.belongsTo(models.Account, {
42     foreignKey: {
43       name: 'accountId',
44       allowNull: false
45     },
46     onDelete: 'CASCADE'
47   })
48
49   AccountFollow.belongsTo(models.Account, {
50     foreignKey: {
51       name: 'targetAccountId',
52       allowNull: false
53     },
54     onDelete: 'CASCADE'
55   })
56 }