I don’t know if this is the case or not, but if you are not requiring a
patient to be assigned elsewhere then some of the records will not have
a patient record. When it loops and reaches one such consult, then the
error will be thrown. You can fix it by giving the line a condition:
Me again. There has got to be a better way of doing what I just wrote
there. With what I have there will be an additional query for each
consult record to see if it has a patient. If you have this in a lot of
rows and columns on a list page, then that’s a lot of queries. It does
the job, but with a lot of extra querying.
I don’t know if this is the case or not, but if you are not requiring a
patient to be assigned elsewhere then some of the records will not have
a patient record. When it loops and reaches one such consult, then the
error will be thrown. You can fix it by giving the line a condition:
<%= consult.patient.name if consult.patient %>
Hope this helps…
thanks a lot robert,
indeed there was a problem in my table, there were some records in it
with no parent. now it works
There has got to be a better way of doing what I just wrote
there. With what I have there will be an additional query for each
consult record to see if it has a patient.
I disliked that by-product as well and instead have been using:
There has got to be a better way of doing what I just wrote
there. With what I have there will be an additional query for each
consult record to see if it has a patient.
I disliked that by-product as well and instead have been using:
<%= consult.patient.name if consult.patient_id %>
Hi Lonnie-
I just tried changing one of my lists to do this, but I’m still showing
individual queries being done. In my application I have help desk
tickets with the following belongs_tos:
department
user
category
assignee
On my list I want to show each of these. In my tickets controller I have
the following:
The :include option should (and does) create joins in the tickets query.
I assume this would then cause those associations to not be loaded
separately. In my view I have the following:
<% for ticket in @tickets %>
#...
<%=h ticket.user.full_name if ticket.user_id %>
<%=h ticket.department.name if ticket.department_id %>
<%=h ticket.category.name if ticket.ticket_category_id %>
<%=h ticket.assignee.full_name if ticket.assignee_id %>
#...
<% end %>
When load the page my terminal window shows individual queries being
done still. Am I missing something?
Thanks,
Robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.