Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egg-sequelize: 由于core项目中loadToApp已经是异步函数,导致在sequelize中没有正确的设置表对象 #5396

Open
hunjixin opened this issue Feb 13, 2025 · 1 comment

Comments

@hunjixin
Copy link

在此输入你需要反馈的 Bug 具体信息(Bug in Detail):

    app.loader.loadToApp(modelDir, target, {
      caseStyle: 'upper',
      ignore: config.exclude,
      filter(model) {
        if (!model || !model.sequelize) return false;
        models.push(model);
        return true;
      },
      initializer(factory) {
        if (typeof factory === 'function') {
          return factory(app, sequelize);
        }
      },
    });
    
//这里由于loadToApp是异步的会直接退出,导致后来的ctx.model上没有具体的表对象
    Object.assign(model[delegate[len - 1]], app[target]);

    models.forEach(model => {
      typeof model.associate === 'function' && model.associate();
    });

    return model[delegate[len - 1]];

可复现问题的仓库地址(Reproduction Repo)

    app.loader.loadToApp(modelDir, target, {
      caseStyle: 'upper',
      ignore: config.exclude,
      filter(model) {
        if (!model || !model.sequelize) return false;
        models.push(model);
        return true;
      },
      initializer(factory) {
        if (typeof factory === 'function') {
          return factory(app, sequelize);
        }
      },
    });
    
//这里由于loadToApp是异步的会直接退出,导致后来的ctx.model上没有具体的表对象
    Object.assign(model[delegate[len - 1]], app[target]);

    models.forEach(model => {
      typeof model.associate === 'function' && model.associate();
    });

    return model[delegate[len - 1]];

Node 版本号:

v23.2.0

Eggjs 版本号:

4.0.9

相关插件名称与版本号(PlugIn and Name):

"egg-sequelize": "^6.0.0",

操作平台与版本号(Platform and Version):

mac

@hunjixin hunjixin changed the title egg-sequelize: 由于core项目中loadToApp已经是异步函数,导致在sequelize中无法获取到model egg-sequelize: 由于core项目中loadToApp已经是异步函数,导致在sequelize中没有正确的设置表对象 Feb 13, 2025
@fengmk2
Copy link
Member

fengmk2 commented Feb 13, 2025

egg-sequelize 还没适配 egg v4,请使用 egg v3

@fengmk2 fengmk2 added this to egg 4.0 Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants