ManyToOne relation with custom column name
See original GitHub issueI’m trying to get setup an example for my mysql-db with real customer data (and tables). Two simple tables called artikel and kollektion have a simple may-to.one relation (many articles may be part of one collection).
`
@Table(“artikel”) export class Artikel {
@PrimaryColumn("int", { generated: true })
@Column({name: "artikel_id"})
id: number;
@Column({name: "artikel_nummer"})
nummer: string;
@Column({name: "artikel_name"})
name: string;
@Column({name: "artikel_extrabarcode"})
extrabarcode: string;
@Column({name: "artikel_saison"})
saison: string;
@ManyToOne(type => Kollektion, { cascadeAll: true })
@Column("int", {name: "id_kollektion"})
kollektion: Kollektion;
}
@Table(“kollektion”) export class Kollektion {
@PrimaryColumn("int", { generated: true })
@Column({name: "kollektion_id"})
id: number;
@Column({name: "kollektion_name"})
name: string;
}
`
In Table Artikel the FK column to table kollektion is named ‘id_kollektion’ and not ‘artikel’.
I tried to specify the different column as shown above by adding a ‘@Column(“int”, {name: “id_kollektion”})’ but when executing a persist I get the following error:
... executing query: START TRANSACTION executing query: INSERT INTO artikel(artikel_nummer, artikel_name, artikel_saison, id_kollektion, kollektion) VALUES ( ?,?,?,?,?) -- PARAMETERS: ["SNB-001","Snowboard WL","winter-2016",{"name":"Burton 2016"},null] executing query: INSERT INTO kollektion(kollektion_name) VALUES (?) -- PARAMETERS: ["Burton 2016"] query failed: INSERT INTO artikel(artikel_nummer, artikel_name, artikel_saison, id_kollektion, kollektion) VALUES (?,? ,?,?,?) -- PARAMETERS: ["SNB-001","Snowboard WL","winter-2016",{"name":"Burton 2016"},null] executing query: ROLLBACK Cannot save. Error: { Error: ER_BAD_FIELD_ERROR: Unknown column 'kollektion' in 'field list' ...
Seems that there is no support for specifying a custom column name. I think this would be a necessary feature for accessing existing database schemas.
Regards, Walter
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
there are other errors as well. Here is correct code:
Hi pleerock, Thank you for your corrections and hints. I will retest the issue and close it if it works as expected.
Regards, Walter