Adding Unscoped() to the call chain like this:
db.Unscoped().Preload("Orders").Find(&users)
affects the Find(), but does not affect the Preload().
The query generated for the Preload() still contains:
"orders"."deleted_at" IS NULL
How can I unscope the generated preload query? I want soft-deleted rows to be fetched by Preload().
Callback can be like this:
.Preload("Orders", func(db *gorm.DB) *gorm.DB {
return db.Unscoped()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With