HowTo?: Eager caching of third order ActiveRecord assoc

Hello.

Using the “:include”, which generates a “LEFT OUTER JOIN” SQL command,
it is possible to eagerly preload second order data objects (children)
for a given association.

I wanted to know, if it is possible to eagerly preload and cache
third order (or more) data objects, which are little-children or
little-little-children. As I’ve seen. it is possible to add
“LEFT OUTER JOIN” SQL clauses with the needed conditions,
to fetch little-little-children data, but how to do this with
ActiveRecord and its cache?

My models are as follow:

Model Software

-----------------------------

class Software < ActiveRecord::Base
has_many :releases, :exclusively_dependent => true
end

Model Release

-----------------------------

class Release < ActiveRecord::Base
belongs_to :software
has_many :acquisitions, :exclusively_dependent => true
end

Model Acquisition

-----------------------------

class Acquisition < ActiveRecord::Base
belongs_to :release
has_and_belongs_to_many :languages
end

Model Language

-----------------------------

class Language < ActiveRecord::Base
has_and_belongs_to_many :acquisitions
end

Is it possible to find(), or paginate() Software-s, while
eagerly preloading in cache their Release-s, the release
Acquisition-s, and the supported Language-s for those releases?
And how to do it?

Thank to all for your suggestions.

On Monday, July 24, 2006, at 2:50 PM, Krassimir T. wrote:

to fetch little-little-children data, but how to do this with

Model Release

has_and_belongs_to_many :languages
Acquisition-s, and the supported Language-s for those releases?
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Try this…

Software.find(:all, :include=>{:releases=>{:aquisitions=>:languages}})

In theory this should work, but YMMV.

_Kevin
www.sciwerks.com

Kevin O. wrote:

On Monday, July 24, 2006, at 2:50 PM, Krassimir T. wrote:

to fetch little-little-children data, but how to do this with

Model Release

has_and_belongs_to_many :languages
Acquisition-s, and the supported Language-s for those releases?
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Try this…

Software.find(:all, :include=>{:releases=>{:aquisitions=>:languages}})

In theory this should work, but YMMV.

_Kevin
www.sciwerks.com

GREAT … IT WORKS …

Thank you very much!

The result is OK, and retreived data is really cached.

Thank you again, Kevin!

Krassimir T. wrote:

Kevin O. wrote:

On Monday, July 24, 2006, at 2:50 PM, Krassimir T. wrote:

to fetch little-little-children data, but how to do this with

Model Release

has_and_belongs_to_many :languages
Acquisition-s, and the supported Language-s for those releases?
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Try this…

Software.find(:all, :include=>{:releases=>{:aquisitions=>:languages}})

In theory this should work, but YMMV.

_Kevin
www.sciwerks.com

GREAT … IT WORKS …

Thank you very much!