Skip to content

QRM of nested query with "double" join on the same table #192

Answered by houten11
emarj asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

I don't see any other way than to create two Account structs:

type Entity struct {
	ID   null.Int `sql:"primary_key"`
	Name string
}

type ToAccount struct {
	ID    null.Int `sql:"primary_key"`
	Name  string
	Owner Entity `alias:"to_owner"`
}

type FromAccount struct {
	ID    null.Int `sql:"primary_key"`
	Name  string
	Owner Entity `alias:"from_owner"`
}

type Transaction struct {
	ID     null.Int    `sql:"primary_key"`
	From   ToAccount   `alias:"From"`
	To     FromAccount `alias:"To"`
	Amount decimal.Decimal
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@emarj
Comment options

@go-jet
Comment options

@emarj
Comment options

@go-jet
Comment options

Answer selected by emarj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants