mysql - 当我创建命令 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;
};
解决方案
推荐阅读
- c# - Datagridview 以不同的顺序显示每个 SQL Server 表中的列
- java - 如何使用流对列表列表中的每个元素求和?
- django-rest-framework - 在 django restframework 中排除返回的表示
- python - 基于有效值的组合聚合
- r - 部署过程中未处理的异常
- android - 尝试 ro 对 pexels API 使用改造,我很新鲜
- java - whitelabel 错误页面 404 spring boot 微服务 Rest Controller
- c# - C# SPOJ 时间优化
- github - GitHub Action appleboy/ssh-action:如何避免 SSH 密钥出现在服务器上?
- swift - SwiftUI 在结构中重复并按数量删除和合并它们