Sequelize findAll is not a function

后端 未结 2 1799
旧时难觅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
    

提交回复
热议问题