web-cat / pythy

Pythy – the Cloud-Based IDE for Novice Python Programmers
18 stars 3 forks source link

Error in course enrollments and users association #56

Closed ArturAguiar closed 10 years ago

ArturAguiar commented 10 years ago

As discussed in the meeting, the error in issue #25 was avoided, but not fixed. I am not too familiar with the "include" tag in a has_many relationship. But based on what I've read it's about resource eager loading and/or efficiency.

I tried changing the original has_many association to use a scope block, but that didn't help. I tried removing each of the includes and order individually, but different errors would pop up.

The only way I found to resolve the issue was to remove the include tag altogether.

Was:

has_many    :course_enrollments, include: [:course_role, :user],
                   order: 'course_roles.id asc, users.full_name asc'

Became (with scope block):

has_many    :course_enrollments, -> { includes(:course_role, :user).order('course_roles.id asc, users.full_name asc') }

Now is:

has_many    :course_enrollments

Would this change cause any problems?

s-edwards commented 10 years ago

I've checked in a different resolution. Read my comment in #25. You can close both of these issues if other uses of the users relationship check out (course_enrollments works perfectly with the fix).

ArturAguiar commented 10 years ago

I agree. That solution looks a lot better. Thank you!