diff options
Diffstat (limited to 'server/models/account/account-follow.ts')
-rw-r--r-- | server/models/account/account-follow.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts new file mode 100644 index 000000000..9bf03b253 --- /dev/null +++ b/server/models/account/account-follow.ts | |||
@@ -0,0 +1,56 @@ | |||
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 | } | ||