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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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)
  end

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

In my view I do this:
<%= link_to_if !system.review.blank?, system.name, :action => 'edit',
:id => system.review %>

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.

Thanks.
This topic is locked and can not be replied to.