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 {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
DeletedAt time.Time
|
DeletedAt *time.Time
|
||||||
}
|
}
|
||||||
DB.AutoMigrate(&User{})
|
DB.AutoMigrate(&User{})
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ type PersonAddress struct {
|
||||||
gorm.JoinTableHandler
|
gorm.JoinTableHandler
|
||||||
PersonID int
|
PersonID int
|
||||||
AddressID int
|
AddressID int
|
||||||
DeletedAt time.Time
|
DeletedAt *time.Time
|
||||||
CreatedAt 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) {
|
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 {
|
if !scope.Search.Unscoped && scope.HasColumn("deleted_at") {
|
||||||
sql := fmt.Sprintf("(%v.deleted_at IS NULL OR %v.deleted_at <= '0001-01-02')", scope.QuotedTableName(), scope.QuotedTableName())
|
sql := fmt.Sprintf("%v.deleted_at IS NULL", quotedTableName)
|
||||||
primaryConditions = append(primaryConditions, sql)
|
primaryConditions = append(primaryConditions, sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !scope.PrimaryKeyZero() {
|
if !scope.PrimaryKeyZero() {
|
||||||
for _, field := range scope.PrimaryFields() {
|
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)
|
primaryConditions = append(primaryConditions, sql)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ type CreditCard struct {
|
||||||
UserId sql.NullInt64
|
UserId sql.NullInt64
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
DeletedAt time.Time
|
DeletedAt *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Email struct {
|
type Email struct {
|
||||||
|
@ -60,7 +60,7 @@ type Address struct {
|
||||||
Post string
|
Post string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
DeletedAt time.Time
|
DeletedAt *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Language struct {
|
type Language struct {
|
||||||
|
|
Loading…
Reference in New Issue