首页 > 解决方案 > 当我创建命令 sequelize 以创建关联表时,它将全部变为小写

问题描述

我是 sequelize/Node/MySql 的新手。我正在遵循指南,并指示 sequelize 为我的两个名为 ProjectAssignments 的资源(用户和项目)创建关联表。它成功创建了表,但将其命名为 projectassignments,这不是很容易阅读,并且在添加更多表时会变得混乱。为什么它会这样做,我该如何改变它?

这是我的两个模型声明:

用户:

"use strict";

import { Model, UUIDV4 } from "sequelize";

interface UserAttributes {
  id: string;
  email: string;
  password: string;
}

module.exports = (sequelize: any, DataTypes: any) => {
  class User extends Model<UserAttributes> implements UserAttributes {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    id!: string;
    email!: string;
    password!: string;
    static associate(models: any) {
      User.belongsToMany(models.Project, {
        through: "ProjectAssignments",
      });
    }
  }
  User.init(
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: UUIDV4,
        allowNull: false,
        primaryKey: true,
      },
      email: { type: DataTypes.STRING, allowNull: false, unique: true },
      password: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    },
    {
      sequelize,
      modelName: "User",
    }
  );
  return User;
};

项目:

"use strict";

import { Model } from "sequelize";

interface ProjectAttributes {
  id: number;
  title: string;
  status: string;
}

module.exports = (sequelize: any, DataTypes: any) => {
  class Project extends Model<ProjectAttributes> implements ProjectAttributes {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */

    id!: number;
    title!: string;
    status!: string;

    static associate(models: any) {
      Project.belongsToMany(models.User, {
        through: "ProjectAssignments",
      });
    }
  }
  Project.init(
    {
      id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
      },
      title: { type: DataTypes.STRING },
      status: { type: DataTypes.STRING },
    },
    {
      sequelize,
      modelName: "Project",
    }
  );
  return Project;
};

标签: mysqlnode.jssequelize.js

解决方案


推荐阅读