How to associated two models in node JS

ساخت وبلاگ
چکیده : I'm trying to make this connection between these two tables, but I'm not getting it and it's giving ... با عنوان : How to associated two models in node JS بخوانید :

I'm trying to make this connection between these two tables, but I'm not getting it and it's giving the following error: "UnhandledPromiseRejectionWarning: SequelizeEagerLoadingError: cfg_user is not associated to dn_coluna!"

follows below the controllers and models that I am using to inner join

This is my cfg_user.js

const sequelizePaginate = require("sequelize-paginate");

module.exports = function(sequelize, DataTypes) {
    const cfg_user = sequelize.define("cfg_user", {
        'id_cfg_user': {
            type: DataTypes.INTEGER(11),
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        'id_cfg_grupo': {
            type: DataTypes.INTEGER(11),
            allowNull: true
        },
        'nome': {
            type: DataTypes.CHAR(100),
            allowNull: true
        },
        'email': {
            type: DataTypes.CHAR(100),
            allowNull: true
        },
        'arquivo': {
            type: DataTypes.CHAR(255),
            allowNull: false
        },
        'senha': {
            type: DataTypes.CHAR(32),
            allowNull: true
        }
    },{
        tableName: "cfg_user",
        freezeTableName: true,
        timestamps: false
    });

    sequelizePaginate.paginate(cfg_user);
    return cfg_user;
};

This is my dn_coluna.js

const sequelizePaginate = require("sequelize-paginate");
const cfg_user = require("./cfg_user");

module.exports = function(sequelize, DataTypes) {
    const dn_coluna = sequelize.define("dn_coluna", {
        'id_dn_coluna': {
            type: DataTypes.INTEGER(10),
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        'id_cfg_user': {
            type: DataTypes.INTEGER(10),
            allowNull: false
        },
        'coluna': {
            type: DataTypes.CHAR(255),
            allowNull: false
        },
        'frase': {
            type: DataTypes.CHAR(255),
            allowNull: true,
        },
        'resumo': {
            type: DataTypes.CHAR(255),
            allowNull: true,
        },
        'url': {
            type: DataTypes.CHAR(255),
            allowNull: true
        },
        'arquivo': {
            type: DataTypes.CHAR(255),
            allowNull: true
        },
        'arquivo_topo': {
            type: DataTypes.CHAR(255),
            allowNull: true
        },
        'arquivo_bg': {
            type: DataTypes.CHAR(255),
            allowNull: true
        },
        'ordem': {
            type: DataTypes.INTEGER(11),
            allowNull: true
        },
        'destaque':{
            type: DataTypes.TINYINT(1),
            allowNull: true
        },
        'libera': {
            type: DataTypes.TINYINT(1),
            allowNull: true
        }
    },{
        tableName: "dn_coluna",
        freezeTableName: true,
        timestamps: false
    });

    sequelizePaginate.paginate(dn_coluna);
    return dn_coluna;
};

this is my Controller

const { dn_coluna } = require("../models");
const { cfg_user } = require("../models");

module.exports = {
    async index(req, res){
        const colunas = await dn_coluna.findAll({
            include: [{
                model: cfg_user,
                attributes: []
            }],
            attributes: ['id_cfg_user'],
        })
        .then(colunas => {
            return res.status(200).json(colunas);
        });
    },
};
back soft...
ما را در سایت back soft دنبال می کنید

نویسنده : استخدام کار بازدید : 7 تاريخ : دوشنبه 3 دی 1397 ساعت: 8:25