douyu0845
2017-01-06 12:35
浏览 237

在golang中与gorm一对多关系不起作用

So i got two tables

type Person struct {
ID int
FirstName string
LastName string
Functions []Function
}
type Function struct {
gorm.Model
Info string
Person Person
}

Now I create the tables like this

db.AutoMigrate(&models.Person{}, &models.Function{})

After this I init the db

user := models.Person{
    FirstName:            "Isa",
    LastName:  "istcool",
    Functions:          []models.Function{{Info: "Trainer"}, {Info: "CEO"}},
}
db.Create(&user)

Now the problem is that my Person table only got Firstname and Lastname column and my Function table only got info column. But when I start my GET request I get people with the column function which is always null.

http://imgur.com/74RU2Va (A screenshot from my GET request and my db) To see my whole programm visit my github repo: https://github.com/Gnadlinger/SpommunicateBackend.git

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题