Multi level :includes for preloading objects from database

I am using :include => :assocation to preload data that I know will be
used later in the UI over and over. However I have data like that that
is an association of one of the associations. How would i preload that
data too?

e.g.

grant has_many :people

and

person belongs_to :group

I can’t include the :group association in a Grant.find because its not
an association of grant, but I use grant.person.group all over the place
so it hits the db every time. How can I include group in the
Grant.find?

thanks.

On 4/20/06, John R. [email protected] wrote:

person belongs_to :group

I can’t include the :group association in a Grant.find because its not
an association of grant, but I use grant.person.group all over the place
so it hits the db every time. How can I include group in the
Grant.find?

thanks.

You can nest the include statements, as of Rails 1.1:
:include => [:grants, {:people => :groups}]

–Wilson.

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