-
-
Notifications
You must be signed in to change notification settings - Fork 415
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment