We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug Hi,
When using the single table inheritance with a schema on the base table, incorrect relations are created.
To Reproduce
Here is the entities:
import { Entity, PrimaryKey, ManyToOne, Enum, type Rel } from "@mikro-orm/postgresql"; @Entity({ tableName: 'users', schema: 'example', discriminatorColumn: 'type', abstract: true }) export class Base { @PrimaryKey() id: string = crypto.randomUUID(); @Enum() type!: 'one' | 'two'; } @Entity({ discriminatorValue: 'one' }) export class One extends Base { } @Entity({ discriminatorValue: 'two' }) export class Two extends Base { } @Entity({ tableName: 'relations' }) export class Relation { @PrimaryKey() id: string = crypto.randomUUID(); @ManyToOne(() => Two, { deleteRule: 'set null' }) appliedBy?: Rel<Two>; }
Here is the migration generated:
async up(): Promise<void> { this.addSql('create schema if not exists "example";'); this.addSql('create table "example"."users" ("id" varchar(255) not null, "type" text check ("type" in (\'one\', \'two\')) not null, constraint "users_pkey" primary key ("id"));'); this.addSql('create index "users_type_index" on "example"."users" ("type");'); this.addSql('create table "relations" ("id" varchar(255) not null, "applied_by_id" varchar(255) not null, constraint "relations_pkey" primary key ("id"));'); this.addSql('alter table "relations" add constraint "relations_applied_by_id_foreign" foreign key ("applied_by_id") references "users" ("id") on update cascade on delete set null;'); }
Expected behavior The foreign key "applied_by_id" references the "users" table without the schema.
Versions
| Dependency | Version | | node | 20 | | mikro-orm | 6.0.0-dev176 | | your-driver | postgresql |
The text was updated successfully, but these errors were encountered:
22e7470
fix(schema): respect explicit schema in FKs to STI entities
cc19ebb
Closes #4933
No branches or pull requests
Describe the bug
Hi,
When using the single table inheritance with a schema on the base table, incorrect relations are created.
To Reproduce
Here is the entities:
Here is the migration generated:
Expected behavior
The foreign key "applied_by_id" references the "users" table without the schema.
Versions
| Dependency | Version |
| node | 20 |
| mikro-orm | 6.0.0-dev176 |
| your-driver | postgresql |
The text was updated successfully, but these errors were encountered: