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
This commit is contained in:
Shubhendra Singh Chauhan 2021-03-08 08:16:43 +05:30 committed by GitHub
parent 02cb40531e
commit 0348b1d3c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 6 deletions

View File

@ -428,9 +428,7 @@ func (schema *Schema) guessRelation(relation *Relationship, field *Field, cgl gu
lookUpNames := []string{lookUpName} lookUpNames := []string{lookUpName}
if len(primaryFields) == 1 { if len(primaryFields) == 1 {
lookUpNames = append(lookUpNames, strings.TrimSuffix(lookUpName, primaryField.Name)+"ID") 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"))
lookUpNames = append(lookUpNames, strings.TrimSuffix(lookUpName, primaryField.Name)+"Id")
lookUpNames = append(lookUpNames, schema.namer.ColumnName(foreignSchema.Table, strings.TrimSuffix(lookUpName, primaryField.Name)+"ID"))
} }
for _, name := range lookUpNames { for _, name := range lookUpNames {

View File

@ -142,7 +142,7 @@ func GetIdentityFieldValuesMap(reflectValue reflect.Value, fields []*Field) (map
if notZero { if notZero {
dataKey := utils.ToStringKey(fieldValues...) dataKey := utils.ToStringKey(fieldValues...)
if _, ok := dataResults[dataKey]; !ok { if _, ok := dataResults[dataKey]; !ok {
results = append(results, fieldValues[:]) results = append(results, fieldValues)
dataResults[dataKey] = []reflect.Value{elem} dataResults[dataKey] = []reflect.Value{elem}
} else { } else {
dataResults[dataKey] = append(dataResults[dataKey], elem) dataResults[dataKey] = append(dataResults[dataKey], elem)

View File

@ -129,7 +129,7 @@ func (sd SoftDeleteDeleteClause) ModifyStatement(stmt *Statement) {
if _, ok := stmt.Clauses["WHERE"]; !stmt.DB.AllowGlobalUpdate && !ok { if _, ok := stmt.Clauses["WHERE"]; !stmt.DB.AllowGlobalUpdate && !ok {
stmt.DB.AddError(ErrMissingWhereClause) stmt.DB.AddError(ErrMissingWhereClause)
} else { } else {
SoftDeleteQueryClause{Field: sd.Field}.ModifyStatement(stmt) SoftDeleteQueryClause(sd).ModifyStatement(stmt)
} }
stmt.AddClauseIfNotExists(clause.Update{}) stmt.AddClauseIfNotExists(clause.Update{})

View File

@ -288,7 +288,7 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
if where, ok := cs.Expression.(clause.Where); ok { if where, ok := cs.Expression.(clause.Where); ok {
if len(where.Exprs) == 1 { if len(where.Exprs) == 1 {
if orConds, ok := where.Exprs[0].(clause.OrConditions); ok { if orConds, ok := where.Exprs[0].(clause.OrConditions); ok {
where.Exprs[0] = clause.AndConditions{Exprs: orConds.Exprs} where.Exprs[0] = clause.AndConditions(orConds)
} }
} }
conds = append(conds, clause.And(where.Exprs...)) conds = append(conds, clause.And(where.Exprs...))