Forum: Ruby on Rails How do I check if something was eagerly loaded?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Joshua S. (Guest)
on 2006-05-24 00:52
(Received via mailing list)
I'm looking for a way to check an item in memory to see if an
association loaded.   I load the association in the controller and then
in the view I need to check to see if the associated model loaded
because I display an attribute of it.  Of course, if the model didn't
load, because it doesn't exist, I get an error. For example, in my
controller I have thus:

  def list
    @systems = System.find(:all, :order => 'name', :include => :review)

:review belongs to a :system, which has_one :review

In my view I do this:
<%= link_to_if !,, :action => 'edit',
:id => %>

This doesn't work, because it queries the database each time (I'm
looping through a collection of 200 items).  So my question is, how can
I get the link_to_if to check the memory object of review, or is there a
different way to test this?  I would think that I could just check
what's in memory and not have to run another query for each item if I
already loaded all of them.

This topic is locked and can not be replied to.