Eager loading issue

Hi,

so I have an eager loading issue I’d like to get opinions on. My models
are imported from an xml file and I’m able to preserve the hierarchy and
use the models to_xml() method to get the whole tree back as an export.
This all works fine. This is an example of structure:

Where I’m having an issue is eager loading of a manufacturer like so:

manufacturer=Manufacturer.find(1, :include=>{:devices=>:capabilities})

The above manufacturer find works the first time and is also a ‘root’
manufacturer which all others can extend (this is how the project was
given to me, I know…). This being the case, I chose to ‘cache’ the root
manufacturer and to do that I put it in my ApplicationController class
and set up a before_filter which checks for a $root_manufacturer global.
If $root_manufacturer isn’t found, then it’s loaded.

Like I said, this all works the first time. But if I try to use
$root_manufacturer.devices, I get the following error in my view:

ActionView::TemplateError undefined method `devices’ for
#Manufacturer:0x35fc6e4

Specifically this line:

<%root_manufacturer.devices.each_with_index do |device,index|%>

When I first loaded the manufacturer into $root_manufacturer global and
checked the length of its devices, it worked. But when I go to the page,
it doesn’t. It seems like not very many people use eager loading - that
I’ve found - so there’s not much out there on this issue. I’m trying to
figure out if maybe for some reason, the devices attribute is falling
off when I try to globalize the manufacturer_root object. It’s strange
too because on the view in the line before the error I have this:

<% logger.debug “#{$root_manufacturer.inspect}”%>

and I can clearly see that <Manufacturer:0x35fc6e4
@devices=[#<Device:0x35fc25c …] …> exists. So I can’t figure out
what’s going on. Any suggestions appreciated. TIA.