How can I limit the amount of associations loaded using pre load? #884
Unanswered
exseniorastronaut
asked this question in
Q&A
Replies: 3 comments 1 reply
-
I'm trying to understand what this means exactly. Do you mean apply like a Otherwise - I'm not sure what you mean. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Ah yeah. This is an unfortunate limitation of the current way eager loading is done. The entire system is slated to be rewritten eventually :( |
Beta Was this translation helpful? Give feedback.
0 replies
-
@aarondl I found a solution that works for Postgresql // uses CTE to generate row number over a specific partition
// It returns all the fields of the table + RowNum
// tableName and partitionName should be escaped and not contain user input as it is unsafe
func RowNum(tableName, partitionName string) QueryMod {
query := fmt.Sprintf("\"%s\" AS (SELECT *, row_number() OVER (PARTITION BY %s) AS RowNum FROM %s)", tableName, partitionName, tableName)
return With(query)
} And then you use it as: models.Users(
qm.Load(
models.UsersRels.Pictures,
RowNum(models.TableNames.Pictures, models.PictureColumns.UserID),
Where("RowNum <= ?", 2),
),
).All(ctx, exec) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think the title says it all. How can I limit the amount of associations loaded using pre load? I understand the challenges with this and I am not sure if the current implementation of eager loading would allow for something like this.
Beta Was this translation helpful? Give feedback.
All reactions