There are several scenarios where generated code (SQL, TS or Java) can produce several tables, columns or classes with the same name.
For example, if you define the following ER model:
User
id int
Users
Role
userId int
UsersRole
Role -> User
User *<->* Role
The following SQL code is produced for SQLite:
PRAGMA foreign_keys = OFF;
CREATE TABLE "users" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"id" INTEGER NOT NULL
);
CREATE TABLE "users" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);
CREATE TABLE "roles" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER NOT NULL,
"user_id" INTEGER NOT NULL,
CONSTRAINT "roles_user_id_unique" UNIQUE ("user_id"),
CONSTRAINT "roles_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "users" ("id")
);
CREATE TABLE "users_roles" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);
CREATE TABLE "users_roles" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER NOT NULL,
"role_id" INTEGER NOT NULL,
CONSTRAINT "users_roles_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "users" ("id"),
CONSTRAINT "users_roles_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "roles" ("id")
);
PRAGMA foreign_keys = ON;
The users and users_roles tables are duplicated, and the same happends to the roles.user_id column. We must implement one of the following solutions:
- Throw an error when this happen.
- Add an incremental suffix to the generated tables and columns
- For example, if the
Role entity has an explicit user_id column, the column produced by the Role -> User relationship must be named user_id2 or something similar.
- The same applies to the corresponding table of the
Users entity. As users table already exists (because the User entity is declared before Users), then the table must be named users2.
- Also, we could return a result with warnings in those cases, as those scenarios are likely to be errors.
There are several scenarios where generated code (SQL, TS or Java) can produce several tables, columns or classes with the same name.
For example, if you define the following ER model:
The following SQL code is produced for SQLite:
The
usersandusers_rolestables are duplicated, and the same happends to theroles.user_idcolumn. We must implement one of the following solutions:Roleentity has an explicituser_idcolumn, the column produced by theRole -> Userrelationship must be nameduser_id2or something similar.Usersentity. Asuserstable already exists (because theUserentity is declared beforeUsers), then the table must be namedusers2.