-
-
Notifications
You must be signed in to change notification settings - Fork 348
Open
Description
Your Question
Is there a way to access field.RelationField outside of the query instance in the current generated code by gorm.gen?
We want to implement a repository method that accepts field.RelationField as variadic arguments for flexible preloading, like this:
func (r *userRepository) GetUserWithPreloads(ctx context.Context, id uint, preloads ...field.RelationField) (*model.User, error) {
query := r.q.User.WithContext(ctx).Where(r.q.User.ID.Eq(id))
for _, preload := range preloads {
query = query.Preload(preload)
}
return query.First()
}Currently, it seems we can only access field.RelationField through the query instance (e.g., query.User.Posts.RelationField). Is there any way to get these relation fields without the query instance, or is there an alternative approach we should consider to achieve flexible and type-safe preloading in the repository layer?
The document you expected this should be explained
Expected answer
We're looking for either:
- A way to access
field.RelationFieldwithout using the query instance in the current generated code. - An alternative approach to implement flexible and type-safe preloading in the repository layer using gorm.gen.
- Confirmation that this is not possible with the current implementation, and whether there are plans to support this kind of usage in future versions.
Thank you for your assistance.
Metadata
Metadata
Assignees
Labels
No labels