Nothing Special   »   [go: up one dir, main page]

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

Nested Relation resulting in Error on Wrong column name #1897

Open
andreastihor opened this issue Jul 14, 2021 · 3 comments
Open

Nested Relation resulting in Error on Wrong column name #1897

andreastihor opened this issue Jul 14, 2021 · 3 comments

Comments

@andreastihor
Copy link

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?

@debendraoli
Copy link

You could use multiple relation calls, Relation("Relation.a").Relation("Relation.b").....

@andreastihor
Copy link
Author

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

@debendraoli
Copy link
debendraoli commented Jul 30, 2021

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")

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

2 participants