我正在使用findAll方法搜索所有用户,但它给出了此错误,无法读取未定义的属性"查找全部"。
用户.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;
我已经使用控制台.log(model.user(检查过,它说未定义,但无法找出导致它的问题用户型号.js
`'use strict';
module.exports = function(sequelize, DataTypes) {
var user = sequelize.define('User', {
name: DataTypes.STRING,
password: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return user;
};
'
"model.user" 未初始化。可能的调试方法是将警报(或控制台.log设置为
alert('model.user is : '+model.user);
或
console.log('model.user is : '+model.user);
根据这些警报,您将能够调试其中哪些是未定义的。如果您能够发现它是未定义的,请检查模型的源代码以查看是否正确定义了"user"。如果上述建议不起作用,请共享模型源。