Your Question
Unable to set custom many2many table, always gets converted to snake case
The document you expected this should be explained
Currently im migratin a java application to golang and the existing join tables are specifically named with Pascal Case ie: ModelOne and ModelTwo with a join table of ModelOneJoinTwo
I have a field in ModelOne as follows:
Many2ManyFieldInModelOne []*ModelTwo `json:"modelTwo" gorm:"many2many:ModelOneJoinToTwo;foreignkey:id;association_foreignkey:id;association_jointable_foreignkey:model_two_id;jointable_foreignkey:modal_one_id"`
however it always changes the name to snakecase: model_one_join_to_two
I have tried a custom NamingStrategy but it yields the same result
I have tried with a custom join table
type ModelOneJoinToTwo struct {
ModelOneId string `json:"modal_one_id" gorm:"column:modal_one_id"`
ModalTwoId string `json:"model_two_id" gorm:"column:model_two_id"`
}
func (m *ModelOneJoinToTwo) TableName() string {
return "ModelOneJoinToTwo"
}
and used like so:
_ = EngineNew.SetupJoinTable(&ModelOne{}, "Many2ManyFieldInModelOne", &ModelOneJoinToTwo{})
when i debug it gets into TableName and returns the correct string but later still gets changes to snake case.
Expected answer
TableName() on the join table to translate to the database calls
Comment From: JunHyungJang
Is this issue still open or need to review further?
Comment From: apuckey
Yes this is still happening, Unless someone has committed something recently to rectify it and not linked this issue.
Comment From: injae-kim
someone has committed something recently to rectify it and not linked this issue.
Hi @apuckey , can you share commit link? we want to try to fix this issue :)
Comment From: apuckey
Hi,
I think you mis-read what i wrote. I was saying unless someone has already committed a fix then its still broken. I'll do some debugging later to try narrow down where the issue is.
Comment From: willthrom
This is still broken.... shouldn't be easy to fix? Or is it lack of man power?