Some course edition statistics consider other courses too
In course edition statistics, there are fields for students with or without groups. However, the ActiveRecord query for those looks as follows:si
@course_edition.approved_participants.with_project.size
This produces an SQL query similar to this:
SELECT COUNT(DISTINCT "users"."id") AS "count_id", "users"."id" AS "users_id"
FROM "users"
INNER JOIN "course_participations" ON "users"."id" = "course_participations"."user_id"
INNER JOIN "memberships" ON "memberships"."user_id" = "users"."id"
INNER JOIN "groups" ON "groups"."id" = "memberships"."group_id"
LEFT OUTER JOIN "offerers" ON "offerers"."actable_type" = "User" AND "offerers"."actable_id" = "users"."id"
WHERE "course_participations"."course_edition_id" = 1 AND "course_participations"."status" = 1 AND "groups"."status" = 2
GROUP BY "users"."id"
In other words, this query returns the number of students who:
- participate in
@course_edition
- have a group in any course edition.
This should only consider groups in the current course edition. Other statistics, such as approved_participants.without_project
, approved_participants.on_interest_list
, etc. have a similar issue.
Suggested fix: instead of following the path course_edition -> course_participation -> user -> membership
, we could do course_edition -> project -> group -> membership -> user
Edited by Martin Mladenov