Nested Relation resulting in Error on Wrong column name
andreastihor opened this issue · 3 comments
So i have 6 table which is table O and has sequential relation of a b c d e
and then I want to access table e value from O i use .Relation
but when I do O.Relation("a.b.c.d.e")
it gives me the wrong column name error which is cannot find column a_b_c_d_ti while the column itself should be title
and when i look at the generated query, it works just fine
Any idea how to solve this? it seems the maximum .Relation() table of go PG still stucks at 3?
You could use multiple relation calls, Relation("Relation.a").Relation("Relation.b").....
uhm, i think you misunderstood the problem, so i have table
order that has relation with voucher that has relation with package that has relation with service that has relation with service type
which makes
o -> v -> p -> s -> st
and I only have the order data which makes me can't do the suggestion you give
Oh, you need to also select the relation column, i guess go-pg is that by design.
for example:
type struct Roles {
id uint
name string
Users []Users
}
type struct Users {
id uint
name string
RoleID uint
}
in order to select get users from role, you also need to select relation column if you have explicit column selection.
example:
// will not work
Model(&Role{})Relation("Users.name")
// will work
Model(&Role{}).Relation("Users.name").Relation("Users.role_id")