change the method of initializing slice
This commit is contained in:
		
							parent
							
								
									3d3208ed60
								
							
						
					
					
						commit
						9e3805f78f
					
				@ -137,7 +137,7 @@ func SaveAfterAssociations(db *gorm.DB) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if elems.Len() > 0 {
 | 
			
		||||
					assignmentColumns := []string{}
 | 
			
		||||
					assignmentColumns := make([]string, 0, len(rel.References))
 | 
			
		||||
					for _, ref := range rel.References {
 | 
			
		||||
						assignmentColumns = append(assignmentColumns, ref.ForeignKey.DBName)
 | 
			
		||||
					}
 | 
			
		||||
@ -151,7 +151,7 @@ func SaveAfterAssociations(db *gorm.DB) {
 | 
			
		||||
						f = f.Addr()
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					assignmentColumns := []string{}
 | 
			
		||||
					assignmentColumns := make([]string, 0, len(rel.References))
 | 
			
		||||
					for _, ref := range rel.References {
 | 
			
		||||
						if ref.OwnPrimaryKey {
 | 
			
		||||
							fv, _ := ref.PrimaryKey.ValueOf(db.Statement.ReflectValue)
 | 
			
		||||
@ -216,7 +216,7 @@ func SaveAfterAssociations(db *gorm.DB) {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if elems.Len() > 0 {
 | 
			
		||||
				assignmentColumns := []string{}
 | 
			
		||||
				assignmentColumns := make([]string, 0, len(rel.References))
 | 
			
		||||
				for _, ref := range rel.References {
 | 
			
		||||
					assignmentColumns = append(assignmentColumns, ref.ForeignKey.DBName)
 | 
			
		||||
				}
 | 
			
		||||
@ -320,7 +320,7 @@ func onConflictOption(stmt *gorm.Statement, s *schema.Schema, selectColumns map[
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(defaultUpdatingColumns) > 0 {
 | 
			
		||||
		var columns []clause.Column
 | 
			
		||||
		columns := make([]clause.Column, 0, len(s.PrimaryFieldDBNames))
 | 
			
		||||
		for _, dbName := range s.PrimaryFieldDBNames {
 | 
			
		||||
			columns = append(columns, clause.Column{Name: dbName})
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,7 @@ func DeleteBeforeAssociations(db *gorm.DB) {
 | 
			
		||||
							withoutConditions := false
 | 
			
		||||
 | 
			
		||||
							if len(db.Statement.Selects) > 0 {
 | 
			
		||||
								var selects []string
 | 
			
		||||
								selects := make([]string, 0, len(db.Statement.Selects))
 | 
			
		||||
								for _, s := range db.Statement.Selects {
 | 
			
		||||
									if s == clause.Associations {
 | 
			
		||||
										selects = append(selects, s)
 | 
			
		||||
 | 
			
		||||
@ -172,7 +172,7 @@ func (m Migrator) CreateTable(values ...interface{}) error {
 | 
			
		||||
 | 
			
		||||
			if !hasPrimaryKeyInDataType && len(stmt.Schema.PrimaryFields) > 0 {
 | 
			
		||||
				createTableSQL += "PRIMARY KEY ?,"
 | 
			
		||||
				primaryKeys := []interface{}{}
 | 
			
		||||
				primaryKeys := make([]interface{}, 0, len(stmt.Schema.PrimaryFieldDBNames))
 | 
			
		||||
				for _, field := range stmt.Schema.PrimaryFields {
 | 
			
		||||
					primaryKeys = append(primaryKeys, clause.Column{Name: field.DBName})
 | 
			
		||||
				}
 | 
			
		||||
@ -439,11 +439,12 @@ func buildConstraint(constraint *schema.Constraint) (sql string, results []inter
 | 
			
		||||
		sql += " ON UPDATE " + constraint.OnUpdate
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var foreignKeys, references []interface{}
 | 
			
		||||
	foreignKeys := make([]interface{}, 0, len(constraint.ForeignKeys))
 | 
			
		||||
	for _, field := range constraint.ForeignKeys {
 | 
			
		||||
		foreignKeys = append(foreignKeys, clause.Column{Name: field.DBName})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	references := make([]interface{}, 0, len(constraint.References))
 | 
			
		||||
	for _, field := range constraint.References {
 | 
			
		||||
		references = append(references, clause.Column{Name: field.DBName})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -88,7 +88,7 @@ var (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	var commonInitialismsForReplacer []string
 | 
			
		||||
	commonInitialismsForReplacer := make([]string, 0, len(commonInitialisms))
 | 
			
		||||
	for _, initialism := range commonInitialisms {
 | 
			
		||||
		commonInitialismsForReplacer = append(commonInitialismsForReplacer, initialism, strings.Title(strings.ToLower(initialism)))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -157,8 +157,7 @@ func GetIdentityFieldValuesMap(reflectValue reflect.Value, fields []*Field) (map
 | 
			
		||||
// GetIdentityFieldValuesMapFromValues get identity map from fields
 | 
			
		||||
func GetIdentityFieldValuesMapFromValues(values []interface{}, fields []*Field) (map[string][]reflect.Value, [][]interface{}) {
 | 
			
		||||
	resultsMap := map[string][]reflect.Value{}
 | 
			
		||||
	results := [][]interface{}{}
 | 
			
		||||
 | 
			
		||||
	results := make([][]interface{}, 0, len(values))
 | 
			
		||||
	for _, v := range values {
 | 
			
		||||
		rm, rs := GetIdentityFieldValuesMap(reflect.Indirect(reflect.ValueOf(v)), fields)
 | 
			
		||||
		for k, v := range rm {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user