Gorm Golang orm associations

后端 未结 5 732
死守一世寂寞
死守一世寂寞 2020-12-13 13:40

I\'m using Go with the GORM ORM. I have the following structs. The relation is simple. One Town has multiple Places and one Place belongs to one Town.

type P         


        
5条回答
  •  伪装坚强ぢ
    2020-12-13 14:24

    First change your model:

    type Place struct {
      ID          int
      Name        string
      Description string
      TownID      int
      Town        Town
    }
    

    And second, make preloading: https://gorm.io/docs/preload.html

提交回复
热议问题