type User struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Languages []Language `gorm:"many2many:user_language_tab;ForeignKey:UserID;References:LanguageID"`
}
type UserLanguage struct {
ID int
LanguageID int `gorm:"ForeignKey:LanguageID;References:Languages.LanguageID"`
UserID int `gorm:"ForeignKey:UserID;References:Users.UserID"`
}
type Language struct {
ID int
LanguageID int
Name string
}
func (User) TableName() string {
return "user_tab"
}
func (Teacher) TableName() string {
return "teacher_tab"
}
func (Language) TableName() string {
return "language_tab"
}
var u []User
err := db.Debug().Preload("Languages").Find(&u).Error
there are the models, User join UserLanguage on UserID and join Language on LanguageID.
I override the tags like https://gorm.io/docs/many_to_many.html#Override-Foreign-Key
In gorm v1.21.7, it report Error 1054 (42S22): Unknown column 'user_language_tab.user_user_id' in 'where clause'
I want to ask:
* How to modify the code to make it works ?
* What dose the joinForeignKey and joinReferences do ? It's necessary for me ?
* If I want to find []Language and preload the Users, Does the tag need to be changed ?
* Is there an updated and detailed document to introduce these override tags ?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨