I have these 2 models:
type Residue struct {
ID int
Name string
Categories []*ResidueCategory `gorm:"many2many:residue_residue_categories"`
}
type ResidueCategory struct {
ID int
Name string
Residues []*Residue `gorm:"many2many:residue_residue_categories"`
}
I already have the residue_residue_categories
table. But the columns are:
- id (int)
- residueId (int, foreign key)
- residueCategoryId (int, foreign key)
And I want to do an append association like:
db.Model(&data).Association("Categories").Append(CategoriesData)
But SQL generate is:
INSERT INTO "residue_residue_categories" ("residue_id","residue_category_id") VALUES (49,4) ON CONFLICT DO NOTHING
As you can see, the columns' names in the insert SQL are not correct.
I've already tried to configure additional fields like:
Categories []*ResidueCategory `gorm:"many2many:residue_residue_categories;foreignkey:residueId;association_foreignkey:residueCategoryId"`
Residues []*Residue `gorm:"many2many:residue_residue_categories;association_foreignkey:residueId;foreignkey:residueCategoryId"`
But weirdly, GORM throws: invalid foreign key: residueId
in a simple GetById
(before the append relation). How I can configure this relation with these custom columns' names?