Defect #32558

Distinct can be removed

Added by jwjw yy almost 3 years ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:


Target version:-
Resolution: Affected version:


In apps/redmine/app/models/project.rb, there is `"#{Member.table_name}.project_id = ?", id).distinct`. which will be translated to `SELECT DISTINCT users.* FROM users INNER JOIN members ON members.user_id = WHERE users.status = 1 AND (members.project_id = ?);`

Actually DISTINCT is not necessary due to the uniqueness constraint in member.rb: `validate: user_id, uniqueness: {:scope => project_id}`, which indicates that for member1(member_id1, user_id, project_id) , and member2(member_id2, user_id, project_id), there is member_id1 = member_id2. Or else the uniqueness constraint will be violated. As a result the join result will not return duplicate users.

Also available in: Atom PDF