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

Gorm settings #98

Closed
Faboslav opened this issue May 6, 2020 · 2 comments
Closed

Gorm settings #98

Faboslav opened this issue May 6, 2020 · 2 comments
Labels
question Further information is requested

Comments

@Faboslav
Copy link

Faboslav commented May 6, 2020

Support

Version: v2.7.0

Hello, is there a way override basic Gorm settings in the global database connection scope, for example auto_preload feature?

@System-Glitch System-Glitch added the question Further information is requested label May 6, 2020
@System-Glitch
Copy link
Member

System-Glitch commented May 6, 2020

Hello!

database.GetConnection() returns *gorm.DB, so you can use it in the same way as you normally would.

I think you were thinking about this kind of setting ?

database.GetConnection().Set("gorm:auto_preload", true)

You can make your configuration changes before starting the server:

func configureDatabase() {
    db := database.GetConnection()
    db.Set("gorm:auto_preload", true)
    // Other settings...
}

func main() {
    configureDatabase()
    goyave.Start(route.Register)
}

Be careful though, if the database.Close() method is called, your settings will be gone.

@Faboslav
Copy link
Author

Maybe i can handle it in some kind of middleware, because of the database.Close() thing, thank you for your response!

This was referenced Sep 10, 2020
Merged
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants