Merge 362fda45ca2f74bc860944ab68c2b9d38200bb3b into 4e34a6d21b63e9a9b701a70be9759e5539bf26e9
This commit is contained in:
		
						commit
						a6da201874
					
				| @ -3,7 +3,6 @@ package callbacks | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"gorm.io/gorm" | ||||
| 	"gorm.io/gorm/clause" | ||||
| @ -373,8 +372,8 @@ func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values) { | ||||
| 				for _, column := range values.Columns { | ||||
| 					if field := stmt.Schema.LookUpField(column.Name); field != nil { | ||||
| 						if v, ok := selectColumns[field.DBName]; (ok && v) || (!ok && !restricted) { | ||||
| 							if !field.PrimaryKey && (!field.HasDefaultValue || field.DefaultValueInterface != nil || | ||||
| 								strings.EqualFold(field.DefaultValue, "NULL")) && field.AutoCreateTime == 0 { | ||||
| 							if !field.PrimaryKey && field.AutoCreateTime == 0 && | ||||
| 								(!field.HasDefaultValue || field.DefaultValueInterface != nil || field.DefaultValue != "") { | ||||
| 								if field.AutoUpdateTime > 0 { | ||||
| 									assignment := clause.Assignment{Column: clause.Column{Name: field.DBName}, Value: curTime} | ||||
| 									switch field.AutoUpdateTime { | ||||
|  | ||||
| @ -598,12 +598,17 @@ func TestCreateWithAutoIncrementCompositeKey(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestCreateOnConflictWithDefaultNull(t *testing.T) { | ||||
| func TestCreateOnConflictWithDefault(t *testing.T) { | ||||
| 	type OnConflictUser struct { | ||||
| 		ID      string | ||||
| 		Name    string `gorm:"default:null"` | ||||
| 		Email   string | ||||
| 		Mobile  string  `gorm:"default:'133xxxx'"` | ||||
| 		Company Company `gorm:"default:'{}';serializer:json"` | ||||
| 	} | ||||
| 
 | ||||
| 	type Company struct { | ||||
| 		Name string | ||||
| 	} | ||||
| 
 | ||||
| 	err := DB.Migrator().DropTable(&OnConflictUser{}) | ||||
| @ -623,6 +628,7 @@ func TestCreateOnConflictWithDefaultNull(t *testing.T) { | ||||
| 	u.Name = "on-conflict-user-name-2" | ||||
| 	u.Email = "on-conflict-user-email-2" | ||||
| 	u.Mobile = "" | ||||
| 	u.Company.Name = "on-conflict-user-company-2" | ||||
| 	err = DB.Clauses(clause.OnConflict{UpdateAll: true}).Create(&u).Error | ||||
| 	AssertEqual(t, err, nil) | ||||
| 
 | ||||
| @ -632,6 +638,7 @@ func TestCreateOnConflictWithDefaultNull(t *testing.T) { | ||||
| 	AssertEqual(t, u2.Name, "on-conflict-user-name-2") | ||||
| 	AssertEqual(t, u2.Email, "on-conflict-user-email-2") | ||||
| 	AssertEqual(t, u2.Mobile, "133xxxx") | ||||
| 	AssertEqual(t, u2.Company.Name, "on-conflict-user-company-2") | ||||
| } | ||||
| 
 | ||||
| func TestCreateFromMapWithoutPK(t *testing.T) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Mo Huishou
						Mo Huishou