Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multiple joins not deserializing correctly #1999

Closed Unanswered
farbodg asked this question in Q&A
Discussion options

I have the following tables:

type Table1 struct {
 tableName models.TableName `pg:"table1"`
 ID string `pg:"id,pk"`
 Table2ID string `pg:"table2_id,notnull"`
 ...
 Table2 *Table2 `pg:"rel:has-one"`
 Table3 *Table3 `pg:"rel:has-one"` // can be has-many
}
type Table2 struct {
 tableName models.TableName `pg:"table2"`
 ID string `pg:"id,pk"`
 ...
}
type Table3 struct {
 tableName models.TableName `pg:"table3"`
 ID string `pg:"id,pk"`
 Table1ID string `pg:"table1_id,notnull"`
 ...
 Table1 *Table1 `pg:"rel:has-one"`
}

And the following query:

return tx.Model(&table1).
 ColumnExpr("table2.*").
 ColumnExpr("table3.*").
 Relation("Table2").
 Relation("Table3").
 Join("INNER JOIN table2").
 JoinOn("table1.table2_id = table2.id").
 Join("INNER JOIN table3").
 JoinOn("table1.id = table3.table1_id").
 Where(...).
 Select()

My results return the records in Table1 and Table2, but not Table3 (Table3 field is nil). How do I go about correctly deserializing the results into the associated structs?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /