Reputation: 148
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().
Upvotes: 4
Views: 3926
Reputation: 206
Callback can be like this:
.Preload("Orders", func(db *gorm.DB) *gorm.DB {
return db.Unscoped()
}
Upvotes: 15