When I try QueryContext function with nested struct, nested struct always get empty struct.
How I solve this?
type User struct {
Firstname *string `json:"firstname" sql:",notnull"`
Lastname *string `json:"lastname" sql:",notnull"`
}
type TestUser struct {
User *User `json:"user"`
}
query := `
SELECT
users.firstname,
users.lastname
FROM
test_users
LEFT JOIN (
SELECT
id, firstname, lastname
FROM
users
) users ON users.id = test_users.user_id
LIMIT 1
`
models := []TestUser{}
_, _ := conn.QueryContext(ctx, &models, query)
return models, nil
If this is impossible with go-pg orm,
Is there any orm function to do that sql?
Thanks
You have to use the ORM model abstraction provided by go-pg.
If you have two
structslike these:Then you can populate your
modelsslice using the.Model