DEV Community

loading...

Discussion on: Need help with sql (*_*) !

Collapse
ohaddahan profile image
ohaddahan

Your query creates an N+1 issue.
Try preloading the associated data:

@appointments = (current_user.admin? ? Appointment.all :    Appointment.current_user(current_user.physician)).
                includes(patient: [:user], physician: [:user])