fixbug:当为非自增主键时,也不作为修改列
This commit is contained in:
parent
886f293211
commit
e229346b00
|
@ -19,11 +19,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (statement *Statement) ifAddColUpdate(col *schemas.Column, includeVersion, includeUpdated, includeNil,
|
func (statement *Statement) ifAddColUpdate(col *schemas.Column, includeVersion, includeUpdated, includeNil,
|
||||||
includeAutoIncr, update bool) (bool, error) {
|
includeAutoIncr, isPrimaryKey, update bool) (bool, error) {
|
||||||
columnMap := statement.ColumnMap
|
columnMap := statement.ColumnMap
|
||||||
omitColumnMap := statement.OmitColumnMap
|
omitColumnMap := statement.OmitColumnMap
|
||||||
unscoped := statement.unscoped
|
unscoped := statement.unscoped
|
||||||
|
if !isPrimaryKey && col.IsPrimaryKey {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
if !includeVersion && col.IsVersion {
|
if !includeVersion && col.IsVersion {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -64,7 +66,7 @@ func (statement *Statement) ifAddColUpdate(col *schemas.Column, includeVersion,
|
||||||
// BuildUpdates auto generating update columnes and values according a struct
|
// BuildUpdates auto generating update columnes and values according a struct
|
||||||
func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
||||||
includeVersion, includeUpdated, includeNil,
|
includeVersion, includeUpdated, includeNil,
|
||||||
includeAutoIncr, update bool) ([]string, []interface{}, error) {
|
includeAutoIncr, isPrimaryKey, update bool) ([]string, []interface{}, error) {
|
||||||
table := statement.RefTable
|
table := statement.RefTable
|
||||||
allUseBool := statement.allUseBool
|
allUseBool := statement.allUseBool
|
||||||
useAllCols := statement.useAllCols
|
useAllCols := statement.useAllCols
|
||||||
|
@ -76,7 +78,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
||||||
|
|
||||||
for _, col := range table.Columns() {
|
for _, col := range table.Columns() {
|
||||||
ok, err := statement.ifAddColUpdate(col, includeVersion, includeUpdated, includeNil,
|
ok, err := statement.ifAddColUpdate(col, includeVersion, includeUpdated, includeNil,
|
||||||
includeAutoIncr, update)
|
includeAutoIncr, isPrimaryKey, update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,6 +145,7 @@ func (session *Session) cacheUpdate(table *schemas.Table, tableName, sqlStr stri
|
||||||
// Update records, bean's non-empty fields are updated contents,
|
// Update records, bean's non-empty fields are updated contents,
|
||||||
// condiBean' non-empty filds are conditions
|
// condiBean' non-empty filds are conditions
|
||||||
// CAUTION:
|
// CAUTION:
|
||||||
|
//
|
||||||
// 1.bool will defaultly be updated content nor conditions
|
// 1.bool will defaultly be updated content nor conditions
|
||||||
// You should call UseBool if you have bool to use.
|
// You should call UseBool if you have bool to use.
|
||||||
// 2.float32 & float64 may be not inexact as conditions
|
// 2.float32 & float64 may be not inexact as conditions
|
||||||
|
@ -189,7 +190,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
|
|
||||||
if session.statement.ColumnStr() == "" {
|
if session.statement.ColumnStr() == "" {
|
||||||
colNames, args, err = session.statement.BuildUpdates(v, false, false,
|
colNames, args, err = session.statement.BuildUpdates(v, false, false,
|
||||||
false, false, true)
|
false, false, false, true)
|
||||||
} else {
|
} else {
|
||||||
colNames, args, err = session.genUpdateColumns(bean)
|
colNames, args, err = session.genUpdateColumns(bean)
|
||||||
}
|
}
|
||||||
|
@ -480,7 +481,7 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac
|
||||||
args := make([]interface{}, 0, len(table.ColumnsSeq()))
|
args := make([]interface{}, 0, len(table.ColumnsSeq()))
|
||||||
|
|
||||||
for _, col := range table.Columns() {
|
for _, col := range table.Columns() {
|
||||||
if !col.IsVersion && !col.IsCreated && !col.IsUpdated {
|
if !col.IsVersion && !col.IsCreated && !col.IsUpdated && !col.IsPrimaryKey {
|
||||||
if session.statement.OmitColumnMap.Contain(col.Name) {
|
if session.statement.OmitColumnMap.Contain(col.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue