Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GORM Database.First(&tableStruct, id) without deleted_at IS NULL

Tags:

go

go-gorm

When tableStruct have gorm.Model inside, how to get first record by id without gorm automatically adding deleted_at IS NULL? Is there such function?

like image 562
Kokizzu Avatar asked Jul 20 '26 19:07

Kokizzu


1 Answers

After reading the source code, there are Unscoped method to prevent adding deleted_at IS NULL

Database.Unscoped().First(&tableStruct, id)
like image 136
Kokizzu Avatar answered Jul 23 '26 19:07

Kokizzu