Browse Source

models/org_team: getUserTeams uses includes always -1 in the IN statement (#4412)

Ensure that the IN clause contains one value at least. The idea is avoid a
syntax error in the SQL sentence and rollbacks in the transactions.
For example:

    ERROR:  syntax error at or near ")"
    LINE 1: ...RE ... and team.id IN ();

We will always add the -1 value in the IN list.
Pablo Saavedra 7 years ago
parent
commit
5906268917
1 changed files with 2 additions and 1 deletions
  1. 2 1
      models/org_team.go

+ 2 - 1
models/org_team.go

@@ -450,10 +450,11 @@ func getUserTeams(e Engine, orgID, userID int64) ([]*Team, error) {
 		return nil, err
 	}
 
-	teamIDs := make([]int64, len(teamUsers))
+	teamIDs := make([]int64, len(teamUsers)+1)
 	for i := range teamUsers {
 		teamIDs[i] = teamUsers[i].TeamID
 	}
+	teamIDs[len(teamUsers)] = -1
 
 	teams := make([]*Team, 0, len(teamIDs))
 	return teams, e.Where("org_id = ?", orgID).In("id", teamIDs).Find(&teams)