How to use PreloadWhere? #567
-
I've discovered I know the signature is Any examples would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
For example, if we only wanted to preload a user's group if the group is 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 |
Beta Was this translation helpful? Give feedback.
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: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.