Is it possible to do an unscoped preload in Golang GORM?

Viewed 1759

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().

1 Answers

Callback can be like this:

.Preload("Orders", func(db *gorm.DB) *gorm.DB {
   return db.Unscoped() 
}
Related