This is only going to retrieve shared badges for `current_student`, isn't it? If I'm reading the query you replaced correctly, it sounds like that would loop through all students in the course. Maybe you want `User::SharedEarnedBadges.where(course: current_course)` or `current_course.shared_earned_badges`?