mirror of https://github.com/go-gorm/gorm.git
DeletedAt's type has to been *time.Time
This commit is contained in:
parent
f574429f5e
commit
5c57885d98
|
@ -45,7 +45,7 @@ func TestSoftDelete(t *testing.T) {
|
|||
type User struct {
|
||||
Id int64
|
||||
Name string
|
||||
DeletedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
}
|
||||
DB.AutoMigrate(&User{})
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ type PersonAddress struct {
|
|||
gorm.JoinTableHandler
|
||||
PersonID int
|
||||
AddressID int
|
||||
DeletedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
|
|
|
@ -159,16 +159,19 @@ func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string)
|
|||
}
|
||||
|
||||
func (scope *Scope) whereSql() (sql string) {
|
||||
var primaryConditions, andConditions, orConditions []string
|
||||
var (
|
||||
quotedTableName = scope.QuotedTableName()
|
||||
primaryConditions, andConditions, orConditions []string
|
||||
)
|
||||
|
||||
if !scope.Search.Unscoped && scope.Fields()["deleted_at"] != nil {
|
||||
sql := fmt.Sprintf("(%v.deleted_at IS NULL OR %v.deleted_at <= '0001-01-02')", scope.QuotedTableName(), scope.QuotedTableName())
|
||||
if !scope.Search.Unscoped && scope.HasColumn("deleted_at") {
|
||||
sql := fmt.Sprintf("%v.deleted_at IS NULL", quotedTableName)
|
||||
primaryConditions = append(primaryConditions, sql)
|
||||
}
|
||||
|
||||
if !scope.PrimaryKeyZero() {
|
||||
for _, field := range scope.PrimaryFields() {
|
||||
sql := fmt.Sprintf("(%v = %v)", scope.Quote(field.DBName), scope.AddToVars(field.Field.Interface()))
|
||||
sql := fmt.Sprintf("%v.%v = %v", quotedTableName, scope.Quote(field.DBName), scope.AddToVars(field.Field.Interface()))
|
||||
primaryConditions = append(primaryConditions, sql)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ type CreditCard struct {
|
|||
UserId sql.NullInt64
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
}
|
||||
|
||||
type Email struct {
|
||||
|
@ -60,7 +60,7 @@ type Address struct {
|
|||
Post string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
}
|
||||
|
||||
type Language struct {
|
||||
|
|
Loading…
Reference in New Issue