Fix test
This commit is contained in:
parent
230342d41b
commit
791cfa4834
|
@ -28,14 +28,13 @@ func (session *Session) genAutoCond(condiBean interface{}) (builder.Cond, error)
|
||||||
for k, v := range c {
|
for k, v := range c {
|
||||||
eq[session.engine.Quote(k)] = v
|
eq[session.engine.Quote(k)] = v
|
||||||
}
|
}
|
||||||
autoCond := builder.Eq(eq)
|
|
||||||
|
|
||||||
if session.statement.RefTable != nil {
|
if session.statement.RefTable != nil {
|
||||||
if col := session.statement.RefTable.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
if col := session.statement.RefTable.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
||||||
return autoCond.And(session.statement.CondDeleted(col)), nil
|
return eq.And(session.statement.CondDeleted(col)), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return autoCond, nil
|
return eq, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ct := reflect.TypeOf(condiBean)
|
ct := reflect.TypeOf(condiBean)
|
||||||
|
@ -43,16 +42,15 @@ func (session *Session) genAutoCond(condiBean interface{}) (builder.Cond, error)
|
||||||
if k == reflect.Ptr {
|
if k == reflect.Ptr {
|
||||||
k = ct.Elem().Kind()
|
k = ct.Elem().Kind()
|
||||||
}
|
}
|
||||||
if k == reflect.Struct {
|
if k != reflect.Struct {
|
||||||
|
return nil, ErrConditionType
|
||||||
|
}
|
||||||
|
|
||||||
condTable, err := session.engine.TableInfo(condiBean)
|
condTable, err := session.engine.TableInfo(condiBean)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.statement.BuildConds(condTable, condiBean, true, true, false, true, false)
|
return session.statement.BuildConds(condTable, condiBean, true, true, false, true, false)
|
||||||
}
|
|
||||||
|
|
||||||
return nil, ErrConditionType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update records, bean's non-empty fields are updated contents,
|
// Update records, bean's non-empty fields are updated contents,
|
||||||
|
@ -189,12 +187,22 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
autoCond := builder.NewCond()
|
var autoCond builder.Cond
|
||||||
if len(condiBean) > 0 {
|
if len(condiBean) > 0 {
|
||||||
autoCond, err = session.genAutoCond(condiBean[0])
|
autoCond, err = session.genAutoCond(condiBean[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if col := table.DeletedColumn(); col != nil && !session.statement.GetUnscoped() { // tag "deleted" is enabled
|
||||||
|
autoCond1 := session.statement.CondDeleted(col)
|
||||||
|
|
||||||
|
if autoCond == nil {
|
||||||
|
autoCond = autoCond1
|
||||||
|
} else {
|
||||||
|
autoCond = autoCond.And(autoCond1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in New Issue