aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-follow.ts
blob: 9bf03b253150180c6c7dc0999ca4cd204e6c3bd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as Sequelize from 'sequelize'

import { addMethodsToModel } from '../utils'
import {
  AccountFollowInstance,
  AccountFollowAttributes,

  AccountFollowMethods
} from './account-follow-interface'

let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes>

export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
  AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
    { },
    {
      indexes: [
        {
          fields: [ 'accountId' ],
          unique: true
        },
        {
          fields: [ 'targetAccountId' ],
          unique: true
        }
      ]
    }
  )

  const classMethods = [
    associate
  ]
  addMethodsToModel(AccountFollow, classMethods)

  return AccountFollow
}

// ------------------------------ STATICS ------------------------------

function associate (models) {
  AccountFollow.belongsTo(models.Account, {
    foreignKey: {
      name: 'accountId',
      allowNull: false
    },
    onDelete: 'CASCADE'
  })

  AccountFollow.belongsTo(models.Account, {
    foreignKey: {
      name: 'targetAccountId',
      allowNull: false
    },
    onDelete: 'CASCADE'
  })
}