Tag name changed: softdelete -> deleted
This commit is contained in:
parent
b510fc584f
commit
42f0fc27ea
|
@ -777,6 +777,8 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
||||||
col.Default = "1"
|
col.Default = "1"
|
||||||
case k == "UPDATED":
|
case k == "UPDATED":
|
||||||
col.IsUpdated = true
|
col.IsUpdated = true
|
||||||
|
case k == "DELETED":
|
||||||
|
col.IsDeleted = true
|
||||||
case strings.HasPrefix(k, "INDEX(") && strings.HasSuffix(k, ")"):
|
case strings.HasPrefix(k, "INDEX(") && strings.HasSuffix(k, ")"):
|
||||||
indexName := k[len("INDEX")+1 : len(k)-1]
|
indexName := k[len("INDEX")+1 : len(k)-1]
|
||||||
indexNames[indexName] = core.IndexType
|
indexNames[indexName] = core.IndexType
|
||||||
|
@ -797,8 +799,6 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
||||||
if !hasNoCacheTag {
|
if !hasNoCacheTag {
|
||||||
hasNoCacheTag = true
|
hasNoCacheTag = true
|
||||||
}
|
}
|
||||||
case k == "SOFTDELETE":
|
|
||||||
col.IsSoftDelete = true
|
|
||||||
case k == "NOT":
|
case k == "NOT":
|
||||||
default:
|
default:
|
||||||
if strings.HasPrefix(k, "'") && strings.HasSuffix(k, "'") {
|
if strings.HasPrefix(k, "'") && strings.HasSuffix(k, "'") {
|
||||||
|
|
10
session.go
10
session.go
|
@ -3404,7 +3404,7 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
|
||||||
|
|
||||||
sqlStr, sqlStrForCache := "", ""
|
sqlStr, sqlStrForCache := "", ""
|
||||||
argsForCache := make([]interface{}, 0, len(args) * 2)
|
argsForCache := make([]interface{}, 0, len(args) * 2)
|
||||||
if session.Engine.unscoped || table.SoftDeleteColumn() == nil { // softdelete is disabled
|
if session.Engine.unscoped || table.DeletedColumn() == nil { // deleted is disabled
|
||||||
sqlStr = fmt.Sprintf("DELETE FROM %v WHERE %v",
|
sqlStr = fmt.Sprintf("DELETE FROM %v WHERE %v",
|
||||||
session.Engine.Quote(session.Statement.TableName()), condition)
|
session.Engine.Quote(session.Statement.TableName()), condition)
|
||||||
|
|
||||||
|
@ -3418,17 +3418,17 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
|
||||||
copy(argsForCache, args)
|
copy(argsForCache, args)
|
||||||
argsForCache = append(session.Statement.Params, argsForCache...)
|
argsForCache = append(session.Statement.Params, argsForCache...)
|
||||||
|
|
||||||
softDeleteCol := table.SoftDeleteColumn()
|
deletedColumn := table.DeletedColumn()
|
||||||
sqlStr = fmt.Sprintf("UPDATE %v SET %v = ? WHERE %v",
|
sqlStr = fmt.Sprintf("UPDATE %v SET %v = ? WHERE %v",
|
||||||
session.Engine.Quote(session.Statement.TableName()),
|
session.Engine.Quote(session.Statement.TableName()),
|
||||||
session.Engine.Quote(softDeleteCol.Name),
|
session.Engine.Quote(deletedColumn.Name),
|
||||||
condition)
|
condition)
|
||||||
|
|
||||||
// !oinume! Insert NowTime to the head of session.Statement.Params
|
// !oinume! Insert NowTime to the head of session.Statement.Params
|
||||||
session.Statement.Params = append(session.Statement.Params, "")
|
session.Statement.Params = append(session.Statement.Params, "")
|
||||||
paramsLen := len(session.Statement.Params)
|
paramsLen := len(session.Statement.Params)
|
||||||
copy(session.Statement.Params[1:paramsLen], session.Statement.Params[0:paramsLen-1])
|
copy(session.Statement.Params[1:paramsLen], session.Statement.Params[0:paramsLen-1])
|
||||||
session.Statement.Params[0] = session.Engine.NowTime(softDeleteCol.SQLType.Name)
|
session.Statement.Params[0] = session.Engine.NowTime(deletedColumn.SQLType.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(session.Statement.Params, args...)
|
args = append(session.Statement.Params, args...)
|
||||||
|
@ -3677,7 +3677,7 @@ func genCols(table *core.Table, session *Session, bean interface{}, useCol bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.IsSoftDelete {
|
if col.IsDeleted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
|
||||||
if !includeAutoIncr && col.IsAutoIncrement {
|
if !includeAutoIncr && col.IsAutoIncrement {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if col.IsSoftDelete {
|
if col.IsDeleted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{},
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.IsSoftDelete && !engine.unscoped { // softdelete enabled
|
if col.IsDeleted && !engine.unscoped { // deleted enabled
|
||||||
colNames = append(colNames, fmt.Sprintf("%v IS NULL", engine.Quote(col.Name)))
|
colNames = append(colNames, fmt.Sprintf("%v IS NULL", engine.Quote(col.Name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue