Joshua Schairbaum
2006-May-23 20:51 UTC
[Rails] How do I check if something was eagerly loaded?
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. -- Posted with http://DevLists.com. Sign up and save your mailbox.