Project

General

Profile

Actions

Defect #32558

open

Distinct can be removed

Added by jwjw yy about 5 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
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.

No data to display

Actions

Also available in: Atom PDF