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.
This commit is contained in:
Pablo Saavedra 2017-05-30 05:24:37 +02:00 committed by 无闻
parent a1d411a018
commit 5906268917

View File

@ -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)