rewrite if-else chain as switch statement (#2121)

From effective Go: https://golang.org/doc/effective_go.html#switch

> It's therefore possible—and idiomatic—to write an if-else-if-else chain as a switch.
This commit is contained in:
Iskander (Alex) Sharipov 2018-10-07 03:49:37 +03:00 committed by Jinzhu
parent f6260a0085
commit 742154be9a
1 changed files with 4 additions and 3 deletions

View File

@ -267,15 +267,16 @@ func (association *Association) Count() int {
query = scope.DB()
)
if relationship.Kind == "many_to_many" {
switch relationship.Kind {
case "many_to_many":
query = relationship.JoinTableHandler.JoinWith(relationship.JoinTableHandler, query, scope.Value)
} else if relationship.Kind == "has_many" || relationship.Kind == "has_one" {
case "has_many", "has_one":
primaryKeys := scope.getColumnAsArray(relationship.AssociationForeignFieldNames, scope.Value)
query = query.Where(
fmt.Sprintf("%v IN (%v)", toQueryCondition(scope, relationship.ForeignDBNames), toQueryMarks(primaryKeys)),
toQueryValues(primaryKeys)...,
)
} else if relationship.Kind == "belongs_to" {
case "belongs_to":
primaryKeys := scope.getColumnAsArray(relationship.ForeignFieldNames, scope.Value)
query = query.Where(
fmt.Sprintf("%v IN (%v)", toQueryCondition(scope, relationship.AssociationForeignDBNames), toQueryMarks(primaryKeys)),