Skip to content
Discussion options

You must be logged in to vote

PreloadWhere is a mod that is passed to a preload.

For example, if we only wanted to preload a user's group if the group is 10, then we do this:

models.Users(
  models.Preload.User.Group(
    psql.PreloadWhere(func(from, to string) {
      return []bob.Expression{
        models.Groups.Columns.AliasedAs(to).ID.EQ(psql.Raw(10)),
      },
    }),
  ),
)

NOTE: This will not prevent loading users in other groups. All users will still be loaded.

The reason the function has the signature func (from, to string) []bob.Expression is because when doing preloads, the table name is usually suffixed with a random string of numbers, so the from and to allow you to know what the table is aliased as.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@absolutejam
Comment options

@stephenafamo
Comment options

Answer selected by stephenafamo
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