Answer the question
In order to leave comments, you need to log in
How to match models in Sequelize?
Hello, I have two models:
const Sequelize = require('sequelize');
const sequelize = require('../database/database')
const accounts_statistics = sequelize.define('accounts_statistics', {
name: {
type: Sequelize.STRING,
allowNull: false,
},
value: {
type: Sequelize.DECIMAL,
allowNull: false,
},
system: {
type: Sequelize.STRING,
allowNull: false,
},
account: {
type: Sequelize.STRING,
allowNull: false,
},
},
{
timestamps: false,
freezeTableName: true,
});
accounts_statistics.removeAttribute('id');
module.exports = accounts_statistics;
const Sequelize = require('sequelize');
const sequelize = require('../database/database')
const statistics_description = sequelize.define('statistics_description', {
name: {
type: Sequelize.STRING,
allowNull: false,
},
title: {
type: Sequelize.STRING,
allowNull: false,
},
short_table: {
type: Sequelize.TINYINT,
allowNull: false,
},
disp_order: {
type: Sequelize.INTEGER,
allowNull: false,
},
},
{
timestamps: false,
freezeTableName: true,
}
);
statistics_description.removeAttribute('id');
module.exports = statistics_description;
const getAccounts_statistics = require('../models/Accounts_statistics');
module.exports.getAccounts_statistics = async (req, res) => {
try {
const arr = await getAccounts_statistics.findAll()
res.status(201).json(arr);
} catch (e) {
console.log(e)
res.status(500).json({
message: 'Server ERROR!'
})
}
}
const getStatistics_description = require('../models/Statistics_description');
module.exports.getStatistics_description = async (req, res) => {
try {
const arr = await getStatistics_description.findAll()
console.log(arr)
res.status(201).json(arr);
} catch (e) {
console.log(e)
res.status(500).json({
message: 'Server ERROR!'
})
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question