Open phoenisx opened 9 months ago
typeorm always creates junction tables with the name you provide in JoinTable.name, and since this name is different from the entity FooFeature you defined, both of them are created.
You can either make both FooFeature and JoinTable have similar names, or u can omit creating the FooFeature manually and use the one typeorm creates
@Entity({ name: "foo_feature" }) // <- table created with name foo_feature
export class FooFeature {
@PrimaryGeneratedColumn('identity')
id: number;
}
@Entity({ name: "foo" })
export class Foo {
@PrimaryGeneratedColumn('identity')
id: number;
@ManyToMany(() => FooFeature)
@JoinTable({
name: "foo_included_features", // <- typeorm uses this to create a table
joinColumn: {
name: "foo",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "foo_feature",
referencedColumnName: "id",
},
})
included: typeorm.Relation<FooFeature[]>;
}
Issue description
Duplicate junction tables created for ManyToMany relation with custom junctional table name
Expected Behavior
The only Junction table that should be created should be the one provided by
@JoinTable({ name: 'name' })
relation decorator.Actual Behavior
When I use
@JoinTable
with a custom name, TypeORM creates two Junction tables. One from its own (default), and one from the name I provided.Steps to reproduce
Create the following Entities with relations as described below:
In When synchronized, or even when generating migration file, I get the two instances of Create Table, as described below:
NOo sure why
foo_included_foo_feature
is getting created, even though I have named my Junction table using@JoinTable
.My Environment
Additional Context
No response
Relevant Database Driver(s)
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, but I don't know how to start. I would need guidance.