我正在使用findAll方法搜索所有用戶,但它給出了此錯誤, 無法讀取未定義的屬性'findAll'。無法讀取未定義的屬性'findAll'
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;
我一直在使用的console.log(model.user)檢查它說不確定的,但不能找出問題導致它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'是'undefined' 也許你指的是哪個'首先在進口是 –
它被稱爲其導入用戶的文件的頂部user' ...但它不解決問題 –