gorm golang one2many same table

后端 未结 1 1385
悲&欢浪女
悲&欢浪女 2021-01-23 23:33

I\'m trying to create a self-reference in a (my)sql table using golang gorm. At the moment my code looks like this:

type Person struct {
    gorm.Model
    Name          


        
相关标签:
1条回答
  • 2021-01-24 00:02

    Fortunately gorm have added lately this feature (reference: here).

    In your case should be like this:

    type Person struct {
      gorm.Model
      Name string
      Children []*Person `gorm:"many2many: children;association_jointable_foreignkey:children_id"`
    }
    
    0 讨论(0)
提交回复
热议问题