File tree Expand file tree Collapse file tree 3 files changed +15
-15
lines changed Expand file tree Collapse file tree 3 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 33module . exports = app => {
44 const { STRING , INTEGER , DATE } = app . Sequelize ;
55
6- return app . model . define ( 'post' , {
6+ const Post = app . model . define ( 'post' , {
77 id : {
88 type : INTEGER ,
99 primaryKey : true ,
@@ -14,11 +14,11 @@ module.exports = app => {
1414 user_id : INTEGER ,
1515 created_at : DATE ,
1616 updated_at : DATE ,
17- } , {
18- classMethods : {
19- associate ( ) {
20- app . model . Post . belongsTo ( app . model . User , { as : 'user' , foreignKey : 'user_id' } ) ;
21- } ,
22- } ,
2317 } ) ;
18+
19+ Post . associate = function ( ) {
20+ app . model . Post . belongsTo ( app . model . User , { as : 'user' , foreignKey : 'user_id' } ) ;
21+ } ;
22+
23+ return Post ;
2424} ;
Original file line number Diff line number Diff line change 33module . exports = app => {
44 const { STRING , INTEGER , DATE } = app . Sequelize ;
55
6- return app . model . define ( 'user' , {
6+ const User = app . model . define ( 'user' , {
77 id : {
88 type : INTEGER ,
99 primaryKey : true ,
@@ -13,11 +13,11 @@ module.exports = app => {
1313 age : INTEGER ,
1414 created_at : DATE ,
1515 updated_at : DATE ,
16- } , {
17- classMethods : {
18- associate ( ) {
19- app . model . User . hasMany ( app . model . Post , { as : 'posts' , foreignKey : 'user_id' } ) ;
20- } ,
21- } ,
2216 } ) ;
17+
18+ User . prototype . associate = function ( ) {
19+ app . model . User . hasMany ( app . model . Post , { as : 'posts' , foreignKey : 'user_id' } ) ;
20+ } ;
21+
22+ return User ;
2323} ;
Original file line number Diff line number Diff line change 55 "private" : true ,
66 "dependencies" : {
77 "egg" : " ^1.4.0" ,
8- "egg-sequelize" : " ^2.1.4 " ,
8+ "egg-sequelize" : " ^3.0.1 " ,
99 "pg" : " ^6.2.4" ,
1010 "pg-hstore" : " ^2.3.2"
1111 },
You can’t perform that action at this time.
0 commit comments