Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structs one-to-many relation #26

Open
lycifer3 opened this issue Apr 15, 2020 · 2 comments
Open

structs one-to-many relation #26

lycifer3 opened this issue Apr 15, 2020 · 2 comments

Comments

@lycifer3
Copy link

lycifer3 commented Apr 15, 2020

is it possible to create structures one to many
db: clickhouse 20.3.5.21

example:

type DomainType struct {
	Id        string      `json:"id"`
	Domain    string      `json:"domain"`
	Date      time.Time   `json:"date"`
	Redirects []*Redirect `json:"redirects"`
}

type Redirect struct {
	Id             sql.NullString `json:"id"`
	RedirectDomain sql.NullString `json:"redirect_domain" db:"redirect_domain"`
	Date           sql.NullTime   `json:"redirect_date" db:"date"`
}

end query:

var result []entity.DomainType
query := sess.Select("*").From("domain").LeftJoin("domain_redirect", "domain.id = domain_redirect.id")

query.LoadStructs(&result)

if this is possible then tell me how, I'm begginer to the golang

@DoubleDi
Copy link
Contributor

Hi! When you join like that, You will be having rows for a struct like this

type DomainType struct {
	Id        string      `json:"id"`
	Domain    string      `json:"domain"`
	Date      time.Time   `json:"date"`
	RedirectDomain sql.NullString `json:"redirect_domain" db:"redirect_domain"`
	Date           sql.NullTime  `json:"redirect_date" db:"date"`
}

@lycifer3
Copy link
Author

I understand that, the question is to get a one-to-many structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants