aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/author.js11
-rw-r--r--server/models/oauth-client.js6
-rw-r--r--server/models/user.js5
3 files changed, 19 insertions, 3 deletions
diff --git a/server/models/author.js b/server/models/author.js
index 8f5b598c8..5835ada99 100644
--- a/server/models/author.js
+++ b/server/models/author.js
@@ -23,6 +23,9 @@ module.exports = function (sequelize, DataTypes) {
23 }, 23 },
24 { 24 {
25 fields: [ 'podId' ] 25 fields: [ 'podId' ]
26 },
27 {
28 fields: [ 'userId' ]
26 } 29 }
27 ], 30 ],
28 classMethods: { 31 classMethods: {
@@ -44,4 +47,12 @@ function associate (models) {
44 }, 47 },
45 onDelete: 'cascade' 48 onDelete: 'cascade'
46 }) 49 })
50
51 this.belongsTo(models.User, {
52 foreignKey: {
53 name: 'userId',
54 allowNull: true
55 },
56 onDelete: 'cascade'
57 })
47} 58}
diff --git a/server/models/oauth-client.js b/server/models/oauth-client.js
index 758c4cf2f..021a34007 100644
--- a/server/models/oauth-client.js
+++ b/server/models/oauth-client.js
@@ -30,8 +30,8 @@ module.exports = function (sequelize, DataTypes) {
30 } 30 }
31 ], 31 ],
32 classMethods: { 32 classMethods: {
33 countTotal,
33 getByIdAndSecret, 34 getByIdAndSecret,
34 list,
35 loadFirstClient 35 loadFirstClient
36 } 36 }
37 } 37 }
@@ -42,8 +42,8 @@ module.exports = function (sequelize, DataTypes) {
42 42
43// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
44 44
45function list (callback) { 45function countTotal (callback) {
46 return this.findAll().asCallback(callback) 46 return this.count().asCallback(callback)
47} 47}
48 48
49function loadFirstClient (callback) { 49function loadFirstClient (callback) {
diff --git a/server/models/user.js b/server/models/user.js
index 631cd96c9..36ed723cc 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -94,6 +94,11 @@ function toFormatedJSON () {
94// ------------------------------ STATICS ------------------------------ 94// ------------------------------ STATICS ------------------------------
95 95
96function associate (models) { 96function associate (models) {
97 this.hasOne(models.Author, {
98 foreignKey: 'userId',
99 onDelete: 'cascade'
100 })
101
97 this.hasMany(models.OAuthToken, { 102 this.hasMany(models.OAuthToken, {
98 foreignKey: 'userId', 103 foreignKey: 'userId',
99 onDelete: 'cascade' 104 onDelete: 'cascade'