File tree Expand file tree Collapse file tree 4 files changed +54
-63
lines changed
Expand file tree Collapse file tree 4 files changed +54
-63
lines changed Original file line number Diff line number Diff line change @@ -7,36 +7,33 @@ module.exports = (Sequelize, DataTypes) => {
77 allowNull : false ,
88 } ,
99 } ,
10- {
11- classMethods : {
12- associate : models => {
13- Comment . hasMany ( models . Comment , {
14- foreignKey : 'commentId' ,
15- as : 'replies' ,
16- onDelete : 'CASCADE' ,
17- } ) ;
10+ ) ;
1811
19- Comment . belongsTo ( models . Comment , {
20- foreignKey : 'commentId' ,
21- as : 'parent' ,
22- onDelete : 'CASCADE' ,
23- } ) ;
12+ Comment . associate = models => {
13+ Comment . hasMany ( models . Comment , {
14+ foreignKey : 'commentId' ,
15+ as : 'replies' ,
16+ onDelete : 'CASCADE' ,
17+ } ) ;
2418
25- Comment . belongsTo ( models . Post , {
26- foreignKey : 'postId ' ,
27- as : 'post ' ,
28- onDelete : 'CASCADE' ,
29- } ) ;
19+ Comment . belongsTo ( models . Comment , {
20+ foreignKey : 'commentId ' ,
21+ as : 'parent ' ,
22+ onDelete : 'CASCADE' ,
23+ } ) ;
3024
31- Comment . belongsTo ( models . User , {
32- foreignKey : 'userId' ,
33- as : 'user' ,
34- onDelete : 'CASCADE' ,
35- } ) ;
36- } ,
37- } ,
38- }
39- ) ;
25+ Comment . belongsTo ( models . Post , {
26+ foreignKey : 'postId' ,
27+ as : 'post' ,
28+ onDelete : 'CASCADE' ,
29+ } ) ;
30+
31+ Comment . belongsTo ( models . User , {
32+ foreignKey : 'userId' ,
33+ as : 'user' ,
34+ onDelete : 'CASCADE' ,
35+ } ) ;
36+ } ;
4037
4138 return Comment ;
4239} ;
Original file line number Diff line number Diff line change @@ -10,25 +10,22 @@ module.exports = (Sequelize, DataTypes) => {
1010 type : DataTypes . TEXT ,
1111 allowNull : true ,
1212 } ,
13- } ,
14- {
15- classMethods : {
16- associate : models => {
17- Post . hasMany ( models . Comment , {
18- foreignKey : 'postId' ,
19- as : 'comments' ,
20- onDelete : 'CASCADE' ,
21- } ) ;
22-
23- Post . belongsTo ( models . User , {
24- foreignKey : 'userId' ,
25- as : 'user' ,
26- onDelete : 'CASCADE' ,
27- } ) ;
28- } ,
29- } ,
3013 }
3114 ) ;
3215
16+ Post . associate = models => {
17+ Post . hasMany ( models . Comment , {
18+ foreignKey : 'postId' ,
19+ as : 'comments' ,
20+ onDelete : 'CASCADE' ,
21+ } ) ;
22+
23+ Post . belongsTo ( models . User , {
24+ foreignKey : 'userId' ,
25+ as : 'user' ,
26+ onDelete : 'CASCADE' ,
27+ } ) ;
28+ } ;
29+
3330 return Post ;
3431} ;
Original file line number Diff line number Diff line change @@ -25,25 +25,22 @@ module.exports = (Sequelize, DataTypes) => {
2525 type : DataTypes . STRING ,
2626 allowNull : false ,
2727 } ,
28- } ,
29- {
30- classMethods : {
31- associate : models => {
32- User . hasMany ( models . Post , {
33- foreignKey : 'userId' ,
34- as : 'posts' ,
35- onDelete : 'CASCADE' ,
36- } ) ;
37-
38- User . hasMany ( models . Comment , {
39- foreignKey : 'userId' ,
40- as : 'comments' ,
41- onDelete : 'CASCADE' ,
42- } ) ;
43- } ,
44- } ,
4528 }
4629 ) ;
4730
31+ User . associate = models => {
32+ User . hasMany ( models . Post , {
33+ foreignKey : 'userId' ,
34+ as : 'posts' ,
35+ onDelete : 'CASCADE' ,
36+ } ) ;
37+
38+ User . hasMany ( models . Comment , {
39+ foreignKey : 'userId' ,
40+ as : 'comments' ,
41+ onDelete : 'CASCADE' ,
42+ } ) ;
43+ } ;
44+
4845 return User ;
4946} ;
Original file line number Diff line number Diff line change 3131 "next-routes" : " ^1.0.40" ,
3232 "passport" : " ^0.3.2" ,
3333 "passport-local" : " ^1.0.0" ,
34- "pg" : " ^6.4.2 " ,
34+ "pg" : " ^7.3.0 " ,
3535 "pg-hstore" : " ^2.3.2" ,
3636 "postcss-cssnext" : " ^2.11.0" ,
3737 "prop-types" : " ^15.5.10" ,
4040 "react-redux" : " ^5.0.6" ,
4141 "redux" : " ^3.7.2" ,
4242 "redux-thunk" : " ^2.2.0" ,
43- "sequelize" : " ^3.30.4 " ,
43+ "sequelize" : " ^4.15.0 " ,
4444 "styled-jsx-postcss" : " ^0.2.0"
4545 }
4646}
You can’t perform that action at this time.
0 commit comments