这一节课应该修改文章创建。

这一节课应该修改文章创建,不然增加 user_id 字段后文章创建那里就报错了。

讨论数量: 2

app/http/controllers/articles_controller.go:75

    _article := article.Article{
        Title:  r.PostFormValue("title"),
        Body:   r.PostFormValue("body"),
        UserID: auth.User().Id,
    }

增加 UserID

2年前 评论

应该修改为 UserID: auth.User().ID,
这里的 ID 跟 models.BaseModel 中的定义的 ID 要一致.
不然还是会报错

app\http\controllers\articles_controller.go:74:29: auth.User().Id undefined (type user.User has no field or method Id)
2年前 评论