What will be the best way to filter on a "preloaded table"? #29
-
Currently when you preload a table (left join), it will alias the related table to Can the alias be predictable or configurable? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The reason for adding the random number is to prevent accidentally messing around with the actual query the user wants to run. And when we consider nested preloading, (i.e. post -> preload author { Furthermore, if we look at it critically, the only things that can affect the preload only without affecting the rest of the query is the columns preloaded, and any nested loader. This is why these are the only things the options can modify. To filter by the related table, we can do a regular join to the new table and filter appropriately models.Posts(
models.PreloadPostAuthor(),
// Add your own join and filter
models.UsersWhere.ID.EQ(10),
models.SelectJoin(ctx).Posts.InnerJoin.Users,
) Most database systems would be able to optimize this query quite well |
Beta Was this translation helpful? Give feedback.
The reason for adding the random number is to prevent accidentally messing around with the actual query the user wants to run.
And when we consider nested preloading, (i.e. post -> preload author {
users table
} -> preload organization -> preload owner {users table
}), the random numbers help prevent collisions.Furthermore, if we look at it critically, the only things that can affect the preload only without affecting the rest of the query is the columns preloaded, and any nested loader. This is why these are the only things the options can modify.
To filter by the related table, we can do a regular join to the new table and filter appropriately