Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient preloading #6978

Open
sintyasin opened this issue Apr 19, 2024 · 0 comments
Open

More efficient preloading #6978

sintyasin opened this issue Apr 19, 2024 · 0 comments
Assignees
Labels
type:question general questions

Comments

@sintyasin
Copy link

Your Question

i'm using the v1 of the library , and i wonder if i'm using eager loading through a preload function like below, will it be faster & efficient if i return the relation with first function?

From this:

tx := mc.mysqlDB.Select("personid").Preload("Person", func(db *gorm.DB) *gorm.DB {
return db.Select("details")
}).First(&book, "id = ?", id)

To this:

tx := mc.mysqlDB.Select("personid").Preload("Person", func(db *gorm.DB) *gorm.DB {
return db.Select("details").First(&Person{})
}).First(&book, "id = ?", id)

The document you expected this should be explained

Expected answer

is the first function a necessary call or is it useless in my case?

@sintyasin sintyasin added the type:question general questions label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

2 participants