type Users struct {
Id int `orm:"pk;auto"`
Username string
Password string
Salt string
Email string `orm:"unique"`
}
type Post struct {
Id int `orm:"pk;auto"`
Users *Users `orm:"rel(fk)"`
Author string
Title string `form:"title,text,Title:" valid:"MinSize(5); MaxSize(20)"`
Description string `form:textarea`
Date time.Time `orm:"auto_now_add;type(datetime)"`
}
Users
に値を割り当てようとしていますが、これは外部キーです。ログインしているユーザーIDを割り当てたい。Users
のユーザーIDをPost
の構造体IDのユーザーIDに割り当てる方法。ユーザーIDを外部キーに割り当てる方法
o := orm.NewOrm()
o.Using("default")
post := models.Post{}
users := models.Users{}
if this.Ctx.Input.Method() == "POST" {
inputs := this.Input()
post.Author = sess.(string)
post.Title = inputs.Get("title")
post.Description = inputs.Get("description")
post.Date = time.Now()
}
誰か助けてください –