N
N
NubasLol2019-11-22 14:15:57
go
NubasLol, 2019-11-22 14:15:57

How to work with linked models in golang?

I ran into a problem using gorm. For example, there is a site model that has relationships with the user model. And that, in turn, has a connection with site.

type User struct {
  ID       int     `json:"id"`
  Sites    []Site  `json:"-"`
}

For example, like this, but if you try to put it in different packages, there will be a cyclic import. Now I have porridge from all models in one package. But this is a nightmare.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zolg, 2019-11-22
@NubasLol

a package is an integral entity
if you have two packages that cannot work without each other - this is one package

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question