// remove possible duplicated records in table project_issue
typeresultstruct{
IssueIDint64
ProjectIDint64
Cntint
}
varresults[]result
iferr:=x.Select("issue_id, project_id, count(*) as cnt").
Table("project_issue").
GroupBy("issue_id, project_id").
Having("count(*) > 1").
Find(&results);err!=nil{
returnerr
}
for_,r:=rangeresults{
ifx.Dialect().URI().DBType==schemas.MSSQL{
if_,err:=x.Exec(fmt.Sprintf("delete from project_issue where id in (SELECT top %d id FROM project_issue WHERE issue_id = ? and project_id = ?)",r.Cnt-1),r.IssueID,r.ProjectID);err!=nil{
returnerr
}
}else{
varids[]int64
iferr:=x.SQL("SELECT id FROM project_issue WHERE issue_id = ? and project_id = ? limit ?",r.IssueID,r.ProjectID,r.Cnt-1).Find(&ids);err!=nil{