Resolved the problem with deletedAt as fixed name, now here takes the gorm:column name
This commit is contained in:
		
							parent
							
								
									7fb9b62c17
								
							
						
					
					
						commit
						bf8bb4ea7a
					
				@ -34,13 +34,19 @@ func deleteCallback(scope *Scope) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if !scope.Search.Unscoped && scope.HasColumn("DeletedAt") {
 | 
			
		||||
			scope.Raw(fmt.Sprintf(
 | 
			
		||||
				"UPDATE %v SET deleted_at=%v%v%v",
 | 
			
		||||
				scope.QuotedTableName(),
 | 
			
		||||
				scope.AddToVars(NowFunc()),
 | 
			
		||||
				addExtraSpaceIfExist(scope.CombinedConditionSql()),
 | 
			
		||||
				addExtraSpaceIfExist(extraOption),
 | 
			
		||||
			)).Exec()
 | 
			
		||||
			for _, field := range scope.Fields() {
 | 
			
		||||
				if field.Name == "DeletedAt" {
 | 
			
		||||
					scope.Raw(fmt.Sprintf(
 | 
			
		||||
						"UPDATE %v SET %v=%v%v%v",
 | 
			
		||||
						scope.QuotedTableName(),
 | 
			
		||||
						scope.Quote(field.DBName),
 | 
			
		||||
						scope.AddToVars(NowFunc()),
 | 
			
		||||
						addExtraSpaceIfExist(scope.CombinedConditionSql()),
 | 
			
		||||
						addExtraSpaceIfExist(extraOption),
 | 
			
		||||
					)).Exec()
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			scope.Raw(fmt.Sprintf(
 | 
			
		||||
				"DELETE FROM %v%v%v",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								gorm.iml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								gorm.iml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<module type="GO_MODULE" version="4">
 | 
			
		||||
  <component name="NewModuleRootManager" inherit-compiler-output="true">
 | 
			
		||||
    <exclude-output />
 | 
			
		||||
    <content url="file://$MODULE_DIR$" />
 | 
			
		||||
    <orderEntry type="jdk" jdkName="Go 1.6" jdkType="Go SDK" />
 | 
			
		||||
    <orderEntry type="sourceFolder" forTests="false" />
 | 
			
		||||
    <orderEntry type="library" name="GOPATH <gorm>" level="project" />
 | 
			
		||||
  </component>
 | 
			
		||||
</module>
 | 
			
		||||
							
								
								
									
										11
									
								
								scope.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								scope.go
									
									
									
									
									
								
							@ -676,11 +676,14 @@ func (scope *Scope) whereSQL() (sql string) {
 | 
			
		||||
		primaryConditions, andConditions, orConditions []string
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	if !scope.Search.Unscoped && scope.HasColumn("deleted_at") {
 | 
			
		||||
		sql := fmt.Sprintf("%v.deleted_at IS NULL", quotedTableName)
 | 
			
		||||
		primaryConditions = append(primaryConditions, sql)
 | 
			
		||||
	if !scope.Search.Unscoped && scope.HasColumn("DeletedAt") {
 | 
			
		||||
		for _, field := range scope.Fields() {
 | 
			
		||||
			if field.Name == "DeletedAt" {
 | 
			
		||||
				sql := fmt.Sprintf("%v.%v IS NULL", quotedTableName, scope.Quote(field.DBName))
 | 
			
		||||
				primaryConditions = append(primaryConditions, sql)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !scope.PrimaryKeyZero() {
 | 
			
		||||
		for _, field := range scope.PrimaryFields() {
 | 
			
		||||
			sql := fmt.Sprintf("%v.%v = %v", quotedTableName, scope.Quote(field.DBName), scope.AddToVars(field.Field.Interface()))
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user