Fix DeletedAt marshalling, close #3598
This commit is contained in:
		
							parent
							
								
									063b1ca0c4
								
							
						
					
					
						commit
						689d6e2331
					
				| @ -3,6 +3,7 @@ package gorm | ||||
| import ( | ||||
| 	"database/sql" | ||||
| 	"database/sql/driver" | ||||
| 	"encoding/json" | ||||
| 	"reflect" | ||||
| 
 | ||||
| 	"gorm.io/gorm/clause" | ||||
| @ -24,6 +25,18 @@ func (n DeletedAt) Value() (driver.Value, error) { | ||||
| 	return n.Time, nil | ||||
| } | ||||
| 
 | ||||
| func (n DeletedAt) MarshalJSON() ([]byte, error) { | ||||
| 	return json.Marshal(n.Time) | ||||
| } | ||||
| 
 | ||||
| func (n *DeletedAt) UnmarshalJSON(b []byte) error { | ||||
| 	err := json.Unmarshal(b, &n.Time) | ||||
| 	if err == nil { | ||||
| 		n.Valid = true | ||||
| 	} | ||||
| 	return err | ||||
| } | ||||
| 
 | ||||
| func (DeletedAt) QueryClauses(f *schema.Field) []clause.Interface { | ||||
| 	return []clause.Interface{SoftDeleteQueryClause{Field: f}} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu