Allow to use tag to disable auto create/update time
This commit is contained in:
		
							parent
							
								
									f7b52bb649
								
							
						
					
					
						commit
						9144969c83
					
				| @ -275,7 +275,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { | |||||||
| 		field.DataType = DataType(dataTyper.GormDataType()) | 		field.DataType = DataType(dataTyper.GormDataType()) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if v, ok := field.TagSettings["AUTOCREATETIME"]; ok || (field.Name == "CreatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) { | 	if v, ok := field.TagSettings["AUTOCREATETIME"]; (ok && utils.CheckTruth(v)) || (!ok && field.Name == "CreatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) { | ||||||
| 		if field.DataType == Time { | 		if field.DataType == Time { | ||||||
| 			field.AutoCreateTime = UnixTime | 			field.AutoCreateTime = UnixTime | ||||||
| 		} else if strings.ToUpper(v) == "NANO" { | 		} else if strings.ToUpper(v) == "NANO" { | ||||||
| @ -287,7 +287,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if v, ok := field.TagSettings["AUTOUPDATETIME"]; ok || (field.Name == "UpdatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) { | 	if v, ok := field.TagSettings["AUTOUPDATETIME"]; (ok && utils.CheckTruth(v)) || (!ok && field.Name == "UpdatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) { | ||||||
| 		if field.DataType == Time { | 		if field.DataType == Time { | ||||||
| 			field.AutoUpdateTime = UnixTime | 			field.AutoUpdateTime = UnixTime | ||||||
| 		} else if strings.ToUpper(v) == "NANO" { | 		} else if strings.ToUpper(v) == "NANO" { | ||||||
|  | |||||||
| @ -263,7 +263,6 @@ func TestSaveHasManyCircularReference(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestAssociationError(t *testing.T) { | func TestAssociationError(t *testing.T) { | ||||||
| 	DB = DB.Debug() |  | ||||||
| 	user := *GetUser("TestAssociationError", Config{Pets: 2, Company: true, Account: true, Languages: 2}) | 	user := *GetUser("TestAssociationError", Config{Pets: 2, Company: true, Account: true, Languages: 2}) | ||||||
| 	DB.Create(&user) | 	DB.Create(&user) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ require ( | |||||||
| 	github.com/jinzhu/now v1.1.5 | 	github.com/jinzhu/now v1.1.5 | ||||||
| 	github.com/lib/pq v1.10.4 | 	github.com/lib/pq v1.10.4 | ||||||
| 	github.com/mattn/go-sqlite3 v1.14.12 // indirect | 	github.com/mattn/go-sqlite3 v1.14.12 // indirect | ||||||
| 	golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect | 	golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect | ||||||
| 	gorm.io/driver/mysql v1.3.2 | 	gorm.io/driver/mysql v1.3.2 | ||||||
| 	gorm.io/driver/postgres v1.3.1 | 	gorm.io/driver/postgres v1.3.1 | ||||||
| 	gorm.io/driver/sqlite v1.3.1 | 	gorm.io/driver/sqlite v1.3.1 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu