[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$f7XAv_MdduXO9VHOuVZ0vPpyMtlhsXZHQ5e6zdXj5Boc":3},{"code":4,"message":5,"data":6},200,"成功",{"id":7,"createdAt":8,"title":9,"content":10,"summary":11,"image":12,"uid":13,"user":14,"categoryId":21,"category":22,"subCategoryId":24,"subCategory":25,"comments":27,"status":17,"reason":12,"notice":12,"visitCount":28,"commentCount":29,"keywords":30},79,"2024-02-05T02:40:00.561Z","midwayjs报错：Model not initialized: Member \\\"getTableName\\\" cannot be called. \\\"User\\\" needs to be added to a Sequelize instance","### 问题\n>Model not initialized: Member \\\"getTableName\\\" cannot be called. \\\"User\\\" needs to be added to a Sequelize instance\n\n### 出现错误的地方：\n```\nasync getAllPosts(body: any) {\n    const { pageSize, pageIndex, userId } = body;\n    let query: Object = {};\n    query[\"offset\"] = (pageIndex !== undefined && pageIndex !== null) ? ((pageIndex - 1) * (pageSize || 10)) : 0;\n    query[\"limit\"] = (pageSize !== undefined && pageSize !== null) ? pageSize : 10;\n    if (userId !== undefined && userId !== null) {\n      query[\"where\"] = {\n        user_id : userId\n      };\n    }\n\n    query[\"include\"] = [User]; \n\n    let result: { rows: HuntingPostForm[]; count: number };\n    try {\n      result = await this.huntingPostModel.findAndCountAll(query)\n    } catch (error) {\n      throw new CommonException(StatusCode.SYS_ERROR, error.message);\n    }\n}\n```\n\n### 解决方法：\n[https://github.com/sequelize/sequelize-typescript/issues/686](https://github.com/sequelize/sequelize-typescript/issues/686) 只能参考\n\n[https://github.com/sequelize/sequelize-typescript#how-to-use-associations-with-repository-mode](https://github.com/sequelize/sequelize-typescript#how-to-use-associations-with-repository-mode) 可以解决\n就是Repository方式的include中，必须还是Repository类型\n\n`query[\"include\"] = [this.huntingRoleModel]; // [this.userModel, this.huntingRoleModel]`","在midwayjs中使用Sequelize的时候，定义model有时候容易出现的问题，这里大家需要注意。","",499668042977349,{"phone":15,"userId":13,"nickName":16,"vipType":17,"avatar":18,"sign":19,"createdAt":20},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":21,"name":23},"IT技术",32,{"id":24,"name":26,"parentId":21},"前端",[],104,0,"midwayjs,midwayjs sequelize,midwayjs develop,midwayjs前端,midwayjs后端,midwayjs开发"]