无法读取未定义的属性'findAll'

时间:2017-06-14 01:44:34

标签: javascript mysql express sequelize.js mean-stack

我正在使用findAll方法搜索所有用户,但它会出现此错误, 无法读取未定义的属性'findAll'。

user.js的

"msg": [
    "Reading package lists...", 
    "Building dependency tree...", 
    "Reading state information...", 
    "Reading extended state information...", 
    "Initializing package states...", 
    "Building tag database...", 
    "No packages will be installed, upgraded, or removed.", 
    "0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", 
    "Need to get 0 B of archives. After unpacking 0 B will be used.", 
    "Reading package lists...", 
    "Building dependency tree...", 
    "Reading state information...", 
    "Reading extended state information...", 
    "Initializing package states...", 
    "Building tag database..."
]

我已经检查过使用console.log(model.user)它说未定义但无法找出导致它的问题 user.js的型号

var user = require("../../models/user");
var sequelize = require('sequelize');
var constants = require("../../config/constants");
var requestHelper = require("../../helpers/request");
var responseHelper = require("../../helpers/response");
var model = require("../../models");

 var main = {
    title: "Hello World",
    statusCode: constants.HTTP.CODES.SUCCESS
}

main.signup = function (req, res, next) {

    var postBody = requestHelper.parseBody(req.body); //requestHelper converts into json format
    var responseBody = {}; `

   if (postBody.name != null && postBody.password != null) {

    model.user.findAll().then(function (emp) { // finding user 

          //...........working......//

                 });
            }
        });
    }
}

  module.exports = main;

`

1 个答案:

答案 0 :(得分:0)

“model.user”未初始化。调试的可能方法是将警报(或console.log)设置为

alert('model.user is : '+model.user); 

console.log('model.user is : '+model.user);

根据这些警报,您将能够调试哪些未定义。如果您能够发现它未定义,请检查模型的来源以查看是否正确定义了“user”。如果上述建议不起作用,请共享模型源。