<table> не связано с <table> - PullRequest
       15

<table> не связано с <table>

0 голосов
/ 15 октября 2019

У меня есть некоторые проблемы с ассоциациями в sequelize. В моей таблице кредитов указаны ссылки с помощью credit_types. credit_types 1: N Credits

Это показывает мне следующую проблему: credit_types не связан с кредитами!

// Models / creditTypes.js

const CreditsTypes = sequelize.define(
  "credit_types",
  {
    credit_t_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    description: {
      type: Sequelize.STRING,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);


module.exports =  CreditsTypes;

// Models/credits.js

const Credits = sequelize.define(
  "credits",
  {
    credit_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    debtor_name: {
      type: Sequelize.STRING,
    },
    total_value: {
      type: Sequelize.NUMBER,
    },
    due_date: {
      type: Sequelize.STRING,
    },
    credit_description: {
      type: Sequelize.STRING,
    },
    credit_t_id: {
      type: Sequelize.INTEGER,
      references: {
        model: "credit_types",
        key: "credit_t_id",
      },
    },
    client_id: {
      type: Sequelize.INTEGER,
    },
  },
  {
    timestamps: false,
    freezeTableName: true,
  }
);

Credits.associate = model => {
  Credits.hasMany(CreditsTypes, { foreignKey: "credit_t_id" });
};

module.exports = Credits;

// controller / client.js

const credit = await Credits.findAll({
        include: [
          {
            model: CreditsTypes,
          },
        ],
      });

Я пробую несколько вещей, но ничего не получается.

...