Defect #32558

Distinct can be removed

Added by jwjw yy over 1 year ago.

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

0%

Category:-
Target version:-
Resolution: Affected version:

Description

In apps/redmine/app/models/project.rb, there is `User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct`. which will be translated to `SELECT DISTINCT users.* FROM users INNER JOIN members ON members.user_id = users.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