Your Question

Suppose I have two structs A and B, which are many to many related.

Now I have a slice of A []A, how to lazy load A.Bs for each A in []A?

The document you expected this should be explained

https://gorm.io/docs/preload.html

I know preload is intended to do this, but what I actually need is to lazy load the relations when needed, not at the beginning.

Expected answer

Is there a simply way to implement this feature? Thanks for your help.

Comment From: hwbrzzl

Any update, please?

Comment From: solnsumei

It would be better we are able to lazy load as the default.

Comment From: apuatcfbd

This is very much necessary. Please take it seriously.

Comment From: hsmfawaz

Eliminating redundant queries for fetching the main record is essential for optimizing performance and reducing resource overhead.

Comment From: turkarshreyash

Any updates on this?