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

Optional Nested Structs #845

Closed
ntbosscher opened this issue Jan 20, 2023 · 1 comment
Closed

Optional Nested Structs #845

ntbosscher opened this issue Jan 20, 2023 · 1 comment

Comments

@ntbosscher
Copy link

ntbosscher commented Jan 20, 2023

I'd like to do the following and have .Armor be set if the join succeeds, and set to nil if the join doesn't match. At the moment I'm having to set all the .Armor columns to nullable types to make it work.

Is this already possible and I'm just "doing it wrong"? or do I need to add a PR to make a feature for this?

type User struct {
    ID int
    Armor *Armor
}

type Armor struct {
    Name string
}

usr := &User{}
db.Get(usr, `select 
         user.id "user.id", armor.name "armor.name"
    from user
    left join armor on armor.user = user.id
    where user.id = 1`) 
@ntbosscher
Copy link
Author

Duplicate of #162, closing

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

1 participant