Check if associations are loaded before lazy loading them?

I noticed that when you use an include on an association, for each
record that does not have an association corresponding to the included
association, an extra sql statement will be executed in order to find
the record which you already know does not exist because it would have
otherwise been fetched by the include already.

To avoid these extra db round trips I would like to check if the
association has already been fetched before I call on the association
and let rails attempt to lazy load it.

Does anyone know how I can do this?

Thanks,
Kris

Kris wrote:

I noticed that when you use an include on an association, for each
record that does not have an association corresponding to the included
association, an extra sql statement will be executed in order to find
the record which you already know does not exist because it would have
otherwise been fetched by the include already.

Rails 1.2 will cache nil association values.


We develop, watch us RoR, in numbers too big to ignore.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs