2
What happens?
仿照官方demo,但是报错
Mini Showcase Repository(REQUIRED)
const NewModel = app.model.define("new", {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
name: STRING(24),
sort: INTEGER(),
des: TEXT(),
main_img: TEXT(),
main_content: TEXT(),
status: INTEGER(),
created_at: DATE,
updated_at: DATE,
});
NewModel.associate = function () {
app.model.NewModel.belongsToMany(app.model.newsCategory, {
as: "Tasks",
through: app.model.categoryForNewModel,
foreignKey: "userId",
});
};
error info
TSError: [egg-core] load file: /Users/skylee/wordspace/merculet-official-website-backend/app/model/news.ts, error: ⨯ Unable to compile TypeScript:
app/model/news.ts(18,12): error TS2339: Property 'associate' does not exist on type 'typeof Model'.
at createTSError (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/ts-node/src/index.ts:261:12)
at getOutput (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/ts-node/src/index.ts:367:40)
at Object.compile (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/ts-node/src/index.ts:558:11)
at Module.m._compile (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/ts-node/src/index.ts:439:43)
at Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Object.require.extensions.<computed> [as .ts] (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.loadFile (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/utils/index.js:27:19)
at getExports (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/loader/file_loader.js:199:23)
at FileLoader.parse (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/loader/file_loader.js:158:25)
at FileLoader.load (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/loader/file_loader.js:67:24)
at AppWorkerLoader.loadToApp (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/loader/egg_loader.js:388:25)
at loadDatabase (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-sequelize/lib/loader.js:101:16)
at module.exports (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-sequelize/lib/loader.js:32:20)
at module.exports (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-sequelize/app.js:4:26)
at Hook.configDidLoad (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/lifecycle.js:91:9)
at Lifecycle.triggerConfigDidLoad (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/lifecycle.js:145:14)
at Lifecycle.triggerConfigWillLoad (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/lifecycle.js:139:10)
at AppWorkerLoader.loadCustomApp (/Users/skylee/wordspace/merculet-official-website-backend/node_modules/egg-core/lib/loader/mixin/custom.js:37:20)
How To Reproduce
Steps to reproduce the behavior: 1. 2.
Expected behavior 1. 2.
Context-
Node Version: v12.16.3
-
Egg Version: "egg": "^2.6.1",
-
Plugin Name: "egg-scripts": "^2.6.0", "egg-sequelize": "^5.2.2",