Skip to content

Commit 0348b1d

Browse files
authoredMar 8, 2021
chore: improve code quality (#4123)
* Combine multiple `append`s into a single call * Clean up copied struct fields with type conversion * Remove unnecessary use of slice
1 parent 02cb405 commit 0348b1d

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed
 

‎schema/relationship.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,7 @@ func (schema *Schema) guessRelation(relation *Relationship, field *Field, cgl gu
428428

429429
lookUpNames := []string{lookUpName}
430430
if len(primaryFields) == 1 {
431-
lookUpNames = append(lookUpNames, strings.TrimSuffix(lookUpName, primaryField.Name)+"ID")
432-
lookUpNames = append(lookUpNames, strings.TrimSuffix(lookUpName, primaryField.Name)+"Id")
433-
lookUpNames = append(lookUpNames, schema.namer.ColumnName(foreignSchema.Table, strings.TrimSuffix(lookUpName, primaryField.Name)+"ID"))
431+
lookUpNames = append(lookUpNames, strings.TrimSuffix(lookUpName, primaryField.Name)+"ID", strings.TrimSuffix(lookUpName, primaryField.Name)+"Id", schema.namer.ColumnName(foreignSchema.Table, strings.TrimSuffix(lookUpName, primaryField.Name)+"ID"))
434432
}
435433

436434
for _, name := range lookUpNames {

‎schema/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func GetIdentityFieldValuesMap(reflectValue reflect.Value, fields []*Field) (map
142142
if notZero {
143143
dataKey := utils.ToStringKey(fieldValues...)
144144
if _, ok := dataResults[dataKey]; !ok {
145-
results = append(results, fieldValues[:])
145+
results = append(results, fieldValues)
146146
dataResults[dataKey] = []reflect.Value{elem}
147147
} else {
148148
dataResults[dataKey] = append(dataResults[dataKey], elem)

‎soft_delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (sd SoftDeleteDeleteClause) ModifyStatement(stmt *Statement) {
129129
if _, ok := stmt.Clauses["WHERE"]; !stmt.DB.AllowGlobalUpdate && !ok {
130130
stmt.DB.AddError(ErrMissingWhereClause)
131131
} else {
132-
SoftDeleteQueryClause{Field: sd.Field}.ModifyStatement(stmt)
132+
SoftDeleteQueryClause(sd).ModifyStatement(stmt)
133133
}
134134

135135
stmt.AddClauseIfNotExists(clause.Update{})

‎statement.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
288288
if where, ok := cs.Expression.(clause.Where); ok {
289289
if len(where.Exprs) == 1 {
290290
if orConds, ok := where.Exprs[0].(clause.OrConditions); ok {
291-
where.Exprs[0] = clause.AndConditions{Exprs: orConds.Exprs}
291+
where.Exprs[0] = clause.AndConditions(orConds)
292292
}
293293
}
294294
conds = append(conds, clause.And(where.Exprs...))

0 commit comments

Comments
 (0)