Updated Issues and Issues Stats functions to include table aliases. This addresses errors involving ambiguous column references when filtering issues by the view type "Mentioning you". (#3269)
This commit is contained in:
parent
60110adc06
commit
e7a4f96fb6
1 changed files with 21 additions and 21 deletions
|
@ -520,55 +520,55 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
|
||||||
sess := x.Limit(setting.IssuePagingNum, (opts.Page-1)*setting.IssuePagingNum)
|
sess := x.Limit(setting.IssuePagingNum, (opts.Page-1)*setting.IssuePagingNum)
|
||||||
|
|
||||||
if opts.RepoID > 0 {
|
if opts.RepoID > 0 {
|
||||||
sess.Where("issue.repo_id=?", opts.RepoID).And("is_closed=?", opts.IsClosed)
|
sess.Where("issue.repo_id=?", opts.RepoID).And("issue.is_closed=?", opts.IsClosed)
|
||||||
} else if opts.RepoIDs != nil {
|
} else if opts.RepoIDs != nil {
|
||||||
// In case repository IDs are provided but actually no repository has issue.
|
// In case repository IDs are provided but actually no repository has issue.
|
||||||
if len(opts.RepoIDs) == 0 {
|
if len(opts.RepoIDs) == 0 {
|
||||||
return make([]*Issue, 0), nil
|
return make([]*Issue, 0), nil
|
||||||
}
|
}
|
||||||
sess.In("repo_id", base.Int64sToStrings(opts.RepoIDs)).And("is_closed=?", opts.IsClosed)
|
sess.In("issue.repo_id", base.Int64sToStrings(opts.RepoIDs)).And("issue.is_closed=?", opts.IsClosed)
|
||||||
} else {
|
} else {
|
||||||
sess.Where("issue.is_closed=?", opts.IsClosed)
|
sess.Where("issue.is_closed=?", opts.IsClosed)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.AssigneeID > 0 {
|
if opts.AssigneeID > 0 {
|
||||||
sess.And("assignee_id=?", opts.AssigneeID)
|
sess.And("issue.assignee_id=?", opts.AssigneeID)
|
||||||
} else if opts.PosterID > 0 {
|
} else if opts.PosterID > 0 {
|
||||||
sess.And("poster_id=?", opts.PosterID)
|
sess.And("issue.poster_id=?", opts.PosterID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.MilestoneID > 0 {
|
if opts.MilestoneID > 0 {
|
||||||
sess.And("milestone_id=?", opts.MilestoneID)
|
sess.And("issue.milestone_id=?", opts.MilestoneID)
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.And("is_pull=?", opts.IsPull)
|
sess.And("issue.is_pull=?", opts.IsPull)
|
||||||
|
|
||||||
switch opts.SortType {
|
switch opts.SortType {
|
||||||
case "oldest":
|
case "oldest":
|
||||||
sess.Asc("created_unix")
|
sess.Asc("issue.created_unix")
|
||||||
case "recentupdate":
|
case "recentupdate":
|
||||||
sess.Desc("updated_unix")
|
sess.Desc("issue.updated_unix")
|
||||||
case "leastupdate":
|
case "leastupdate":
|
||||||
sess.Asc("updated_unix")
|
sess.Asc("issue.updated_unix")
|
||||||
case "mostcomment":
|
case "mostcomment":
|
||||||
sess.Desc("num_comments")
|
sess.Desc("issue.num_comments")
|
||||||
case "leastcomment":
|
case "leastcomment":
|
||||||
sess.Asc("num_comments")
|
sess.Asc("issue.num_comments")
|
||||||
case "priority":
|
case "priority":
|
||||||
sess.Desc("priority")
|
sess.Desc("issue.priority")
|
||||||
default:
|
default:
|
||||||
sess.Desc("created_unix")
|
sess.Desc("issue.created_unix")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.Labels) > 0 && opts.Labels != "0" {
|
if len(opts.Labels) > 0 && opts.Labels != "0" {
|
||||||
labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ","))
|
labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ","))
|
||||||
if len(labelIDs) > 0 {
|
if len(labelIDs) > 0 {
|
||||||
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").In("label_id", labelIDs)
|
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").In("issue.label_id", labelIDs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.IsMention {
|
if opts.IsMention {
|
||||||
sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").And("is_mentioned = ?", true)
|
sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").And("issue_user.is_mentioned = ?", true)
|
||||||
|
|
||||||
if opts.UserID > 0 {
|
if opts.UserID > 0 {
|
||||||
sess.And("issue_user.uid = ?", opts.UserID)
|
sess.And("issue_user.uid = ?", opts.UserID)
|
||||||
|
@ -841,16 +841,16 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
|
||||||
case FM_MENTION:
|
case FM_MENTION:
|
||||||
stats.OpenCount, _ = countSession(opts).
|
stats.OpenCount, _ = countSession(opts).
|
||||||
Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
|
Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
|
||||||
And("uid = ?", opts.UserID).
|
And("issue_user.uid = ?", opts.UserID).
|
||||||
And("is_mentioned = ?", true).
|
And("issue_user.is_mentioned = ?", true).
|
||||||
And("is_closed = ?", false).
|
And("issue.is_closed = ?", false).
|
||||||
Count(&Issue{})
|
Count(&Issue{})
|
||||||
|
|
||||||
stats.ClosedCount, _ = countSession(opts).
|
stats.ClosedCount, _ = countSession(opts).
|
||||||
Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
|
Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
|
||||||
And("uid = ?", opts.UserID).
|
And("issue_user.uid = ?", opts.UserID).
|
||||||
And("is_mentioned = ?", true).
|
And("issue_user.is_mentioned = ?", true).
|
||||||
And("is_closed = ?", true).
|
And("issue.is_closed = ?", true).
|
||||||
Count(&Issue{})
|
Count(&Issue{})
|
||||||
}
|
}
|
||||||
return stats
|
return stats
|
||||||
|
|
Reference in a new issue