Hey all, I'm developing a block that needs to look up all the role assignments for a course. The query I'm using for this is:
SELECT ra.roleid, ra.userid
FROM role_assignments AS ra
LEFT OUTER JOIN context AS ctx
ON ctx.id = ra.contextid
LEFT OUTER JOIN course AS c
ON c.id = ctx.instanceid WHERE c.id = " . $course->id;
So when I do this with a test course id from the mysql command line I get 33 listings which is correct based on the user_enrolments table but when I call this command using $DB->get_records_sql() it only returns 2 or 3 entries the teacher, the TA if there is one and a single student usually the last one in the listings i get from running the sql from the command line.
I can't seem to think of anything that could cause this. I would just use the user_enrollments table but I'd really like to know why this is happening. Especially if its a bug with get_records_sql(), but if that was the case I feel like I'd be having similar problems with other queries and I'm not.