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.
|
// CondDeleted returns the conditions whether a record is soft deleted.
|
||||||
func (engine *Engine) CondDeleted(colName string) builder.Cond {
|
func (engine *Engine) CondDeleted(col *core.Column) builder.Cond {
|
||||||
cond := builder.IsNull{colName}.Or(builder.Eq{colName: 0})
|
var cond builder.Cond
|
||||||
if engine.dialect.DBType() == core.MSSQL {
|
if col.SQLType.IsNumeric() {
|
||||||
return cond
|
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
|
// 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
|
if col.IsDeleted && !unscoped { // tag "deleted" is enabled
|
||||||
conds = append(conds, engine.CondDeleted(colName))
|
conds = append(conds, engine.CondDeleted(col))
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldValue := *fieldValuePtr
|
fieldValue := *fieldValuePtr
|
||||||
|
|
|
@ -121,7 +121,7 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
||||||
colName = session.engine.Quote(nm) + "." + colName
|
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 !condBeanIsStruct && table != nil {
|
||||||
if col := table.DeletedColumn(); col != nil && !session.statement.unscoped { // tag "deleted" is enabled
|
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 {
|
if autoCond == nil {
|
||||||
autoCond = autoCond1
|
autoCond = autoCond1
|
||||||
|
|
Loading…
Reference in New Issue