The double join is happening because of the merge. Rails basically doesn't know how to merge other than by doing the relation joins again. You can get around that by specifying the subquery, instead of using `merge`. For example: `.where{student_assignment.student.id.in Student.visible(user)}`

Remember that if we change the joins to include the assignment, student.whatever has to be replaced with student_assignment.student.whatever