I will need to join with recursive, something like this :
SELECT a.*, b.* c.* FROM a
LEFT JOIN b on b.id = a.b_id
LEFT JOIN c ON c.id = b.c_id
And my model definition is :
type A struct {
ID int,
NameA string,
B_id int
B *B,
C *C,
}
type B struct {
ID int,
C_id int,
NameB string,
C C,
}
type C struct {
ID int,
NameC string,
}
I try to use the Relation but didn't works :
a := A{}
//does not work
db.Model(&a).Relation("B").Relation("C").First()
//works
db.Model(&a).Relation("B").First()
How I can achieve the recursive join on go-pg, please let me know if anyone has experience with it. Thanks alot.
You will need to indicate that it's actually a relation on the second struct:
db.Model(&a).Relation("B").Relation("B.C").First()