Skip to content

PreloadWhere Documentation/Examples #172

Closed Answered by stephenafamo
daddz asked this question in Q&A
Discussion options

You must be logged in to vote

The best way to do this at the moment is to do a fresh join and then filter as you would:

	videos, err := models.Videos.Query(ctx, db,
		models.PreloadVideoUser(),
		models.SelectJoins(ctx).Videos.InnerJoin.User,
		models.SelectWhere.Users.ID.GT(200),
	).One()

The generated query will has 2 joins, but the DB is smart enough to do the work just once. You can verify this using EXPLAIN ANALYZE


Why can't PreloadX take WhereMods?

The reason is that to preload, a random suffix is added to the name of the table. This isolates it from the rest of the query and makes it extremely unlikely that it conflicts with any other part of the query.

So, if you wanted to filter using the same join that was …

Replies: 2 comments 13 replies

Comment options

You must be logged in to vote
12 replies
@daddz
Comment options

@stephenafamo
Comment options

@stephenafamo
Comment options

@stephenafamo
Comment options

@daddz
Comment options

Answer selected by stephenafamo
Comment options

You must be logged in to vote
1 reply
@stephenafamo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #171 on February 02, 2024 16:33.