Sequelize findAll is not a function

后端 未结 2 1800
旧时难觅i
旧时难觅i 2021-02-08 19:45

I\'m making a project with Sequelize and I\'m stucked in this step. The problem is that when I try to log in and the passport-local code is executed, when it reaches the

相关标签:
2条回答
  • 2021-02-08 19:49

    The nuke_users module is exporting a function that, when called, returns the Model. Because you aren't calling this function, it is not returning the Model, and thus the function you are looking for does not exist.

    To call this exported function you would need to pass in the sequelize instance and DataTypes, as so:

    var User = require('../models/nuke_users')(sequelize, DataTypes);
    

    In your case you are using a loader in the index.js file, and it is exporting the db object which contains the models keyed by their name.

    var models = require('../models'); // loads index.js
    var User = models.nuke_user;       // the model keyed by its name
    User.findOne(...);                 // search the model
    
    0 讨论(0)
  • 2021-02-08 20:05

    Instead of returning the model, export it from NukeUser.js:

    const NukeUser = sequelize.define('nuke_users', {
        // ...
    });
    
    module.exports = NukeUser;
    

    Then in index.js:

    const NukeUser = require('../models/NukeUser');
    NukeUser.findAll() //.then() ...
    
    0 讨论(0)
提交回复
热议问题