Pārlūkot izejas kodu

fix conflicts between Cols and updated

xormplus 8 gadi atpakaļ
vecāks
revīzija
ceaa87a69d
2 mainītis faili ar 30 papildinājumiem un 11 dzēšanām
  1. 13 11
      session_update.go
  2. 17 0
      session_update_test.go

+ 13 - 11
session_update.go

@@ -202,17 +202,19 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
 	table := session.statement.RefTable
 
 	if session.statement.UseAutoTime && table != nil && table.Updated != "" {
-		colNames = append(colNames, session.engine.Quote(table.Updated)+" = ?")
-		col := table.UpdatedColumn()
-		val, t := session.engine.NowTime2(col.SQLType.Name)
-		args = append(args, val)
-
-		var colName = col.Name
-		if isStruct {
-			session.afterClosures = append(session.afterClosures, func(bean interface{}) {
-				col := table.GetColumn(colName)
-				setColumnTime(bean, col, t)
-			})
+		if _, ok := session.statement.columnMap[strings.ToLower(table.Updated)]; !ok {
+			colNames = append(colNames, session.engine.Quote(table.Updated)+" = ?")
+			col := table.UpdatedColumn()
+			val, t := session.engine.NowTime2(col.SQLType.Name)
+			args = append(args, val)
+
+			var colName = col.Name
+			if isStruct {
+				session.afterClosures = append(session.afterClosures, func(bean interface{}) {
+					col := table.GetColumn(colName)
+					setColumnTime(bean, col, t)
+				})
+			}
 		}
 	}
 

+ 17 - 0
session_update_test.go

@@ -1153,3 +1153,20 @@ func TestNewUpdate(t *testing.T) {
 	assert.NoError(t, err)
 	assert.EqualValues(t, 0, af)
 }
+
+func TestUpdateUpdate(t *testing.T) {
+	assert.NoError(t, prepareEngine())
+
+	type PublicKeyUpdate struct {
+		Id          int64
+		UpdatedUnix int64 `xorm:"updated"`
+	}
+
+	assertSync(t, new(PublicKeyUpdate))
+
+	cnt, err := testEngine.ID(1).Cols("updated_unix").Update(&PublicKeyUpdate{
+		UpdatedUnix: time.Now().Unix(),
+	})
+	assert.NoError(t, err)
+	assert.EqualValues(t, 0, cnt)
+}