Add sql type check on deleted cond
This commit is contained in:
parent
d6e31ce715
commit
92bb9f5e4d
17
engine.go
17
engine.go
|
@ -91,12 +91,19 @@ func (engine *Engine) BufferSize(size int) *Session {
|
|||
}
|
||||
|
||||
// CondDeleted returns the conditions whether a record is soft deleted.
|
||||
func (engine *Engine) CondDeleted(colName string) builder.Cond {
|
||||
cond := builder.IsNull{colName}.Or(builder.Eq{colName: 0})
|
||||
if engine.dialect.DBType() == core.MSSQL {
|
||||
return cond
|
||||
func (engine *Engine) CondDeleted(col *core.Column) builder.Cond {
|
||||
var cond builder.Cond
|
||||
if col.SQLType.IsNumeric() {
|
||||
cond = builder.Eq{col.Name: 0}
|
||||
} else {
|
||||
cond = builder.Eq{col.Name: zeroTime1}
|
||||
}
|
||||
return cond.Or(builder.Eq{colName: zeroTime1})
|
||||
|
||||
if col.Nullable {
|
||||
cond = cond.Or(builder.IsNull{col.Name})
|
||||
}
|
||||
|
||||
return cond
|
||||
}
|
||||
|
||||
// ShowSQL show SQL statement or not on logger if log level is great than INFO
|
||||
|
|
|
@ -58,7 +58,7 @@ func (engine *Engine) buildConds(table *core.Table, bean interface{},
|
|||
}
|
||||
|
||||
if col.IsDeleted && !unscoped { // tag "deleted" is enabled
|
||||
conds = append(conds, engine.CondDeleted(colName))
|
||||
conds = append(conds, engine.CondDeleted(col))
|
||||
}
|
||||
|
||||
fieldValue := *fieldValuePtr
|
||||
|
|
|
@ -121,7 +121,7 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
|||
colName = session.engine.Quote(nm) + "." + colName
|
||||
}
|
||||
|
||||
autoCond = session.engine.CondDeleted(colName)
|
||||
autoCond = session.engine.CondDeleted(col)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
|
||||
if !condBeanIsStruct && table != nil {
|
||||
if col := table.DeletedColumn(); col != nil && !session.statement.unscoped { // tag "deleted" is enabled
|
||||
autoCond1 := session.engine.CondDeleted(session.engine.Quote(col.Name))
|
||||
autoCond1 := session.engine.CondDeleted(col)
|
||||
|
||||
if autoCond == nil {
|
||||
autoCond = autoCond1
|
||||
|
|
Loading…
Reference in New Issue