From 2c335025039a607d8f1add0208d4089b3211800d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 18 Feb 2014 10:03:14 +0800 Subject: [PATCH] Add tests for updated_at will be updated when update value with Assign --- main.go | 2 +- main_test.go | 7 ++++++- scope_private.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index a1b6c5f9..ca1d24bb 100644 --- a/main.go +++ b/main.go @@ -8,8 +8,8 @@ import ( type DB struct { Value interface{} - callback *callback Error error + callback *callback db sqlCommon parent *DB search *search diff --git a/main_test.go b/main_test.go index 59f9a0ea..6d89659a 100644 --- a/main_test.go +++ b/main_test.go @@ -10,7 +10,6 @@ import ( "github.com/jinzhu/gorm" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" - _ "github.com/mattn/go-sqlite3" "os" "reflect" @@ -1105,6 +1104,12 @@ func TestFindOrCreate(t *testing.T) { t.Errorf("user should be created with search value and attrs") } + updated_at1 := user4.UpdatedAt + db.Where(&User{Name: "find or create 3"}).Assign("age", 55).FirstOrCreate(&user4) + if updated_at1.Format(time.RFC3339Nano) == user4.UpdatedAt.Format(time.RFC3339Nano) { + t.Errorf("UpdateAt should be changed when update values with assign") + } + db.Where(&User{Name: "find or create 4"}).Assign(User{Age: 44}).FirstOrCreate(&user4) if user4.Name != "find or create 4" || user4.Id == 0 || user4.Age != 44 { t.Errorf("user should be created with search value and assigned attrs") diff --git a/scope_private.go b/scope_private.go index 919d4b21..dae943e8 100644 --- a/scope_private.go +++ b/scope_private.go @@ -324,7 +324,7 @@ func (scope *Scope) sqlTagForField(field *Field) (tag string) { } } - if len(tag) == 0 && tag != "-" { + if len(tag) == 0 { if field.isPrimaryKey { tag = scope.Dialect().PrimaryKeyTag(value, size) } else {