join using Goqu and scan the results into a struct containing an array of another struct

227 views Asked by At
type selectUserWithOrders struct {
 id int
 name string 
 orders []order
}

type order struct {
 id int
 total int
}

// user table columns are -> id , name, password
// orders table columns are -> id, user_id(fk), order_value 

func (r *Repository) SelectOne(
    id int,
) (selectUserWithOrders, bool, error) {
    var user selectUserWithOrders
    exists, err := r.goquDB.From(
        TABLE,
    ).Select(
    ).Where(goqu.C(ID).Eq(id)).ScanStruct(&user)
    if err != nil {
        return selectUserWithOrders{}, false, err
    }
    return user, exists, nil
}

i am trying to do join on user and order table using user id

I am unable to find solution to do this in single query or or without use of loop

0

There are 0 answers