mirror of https://github.com/go-gorm/gorm.git
Add tests for updated_at will be updated when update value with Assign
This commit is contained in:
parent
c25f26149e
commit
2c33502503
2
main.go
2
main.go
|
@ -8,8 +8,8 @@ import (
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
Value interface{}
|
Value interface{}
|
||||||
callback *callback
|
|
||||||
Error error
|
Error error
|
||||||
|
callback *callback
|
||||||
db sqlCommon
|
db sqlCommon
|
||||||
parent *DB
|
parent *DB
|
||||||
search *search
|
search *search
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -1105,6 +1104,12 @@ func TestFindOrCreate(t *testing.T) {
|
||||||
t.Errorf("user should be created with search value and attrs")
|
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)
|
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 {
|
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")
|
t.Errorf("user should be created with search value and assigned attrs")
|
||||||
|
|
|
@ -324,7 +324,7 @@ func (scope *Scope) sqlTagForField(field *Field) (tag string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tag) == 0 && tag != "-" {
|
if len(tag) == 0 {
|
||||||
if field.isPrimaryKey {
|
if field.isPrimaryKey {
|
||||||
tag = scope.Dialect().PrimaryKeyTag(value, size)
|
tag = scope.Dialect().PrimaryKeyTag(value, size)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue