gothinkster / golang-gin-realworld-example-app

Exemplary real world application built with Golang + Gin
https://realworld.io
MIT License
2.52k stars 497 forks source link

Issue with cyclic dependency #14

Closed utsavgupta closed 3 years ago

utsavgupta commented 5 years ago

I see that the the ArticleUserModel structure contains a reference to models.User.

That is I get the reference of the author (a user object).

But what if I want to list all the articles written by a given user ? I would need a reference of models.Article in the user model. Wouldn't that cause a cyclic dependency error ?

How can we get around this problem ? Other than extracting the models in a separate package outside both user and article ?

wangzitian commented 5 years ago

Sorry for the delay, I think you could write another api, depend on the user and article or other data models. Then, alias/redirect the router to the new api.