Forum: Ruby on Rails eager loading with acts_as_tree

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
R. Elliott M. (Guest)
on 2007-03-11 03:29
Sigh, I have a new problem every day.

Okay I have a model that acts_as_tree, so I am trying to eager load the
objects + all of their children, plus their children's children, and so
on.  However, :include => :children alone doesn't do this, and so far
I've got something like:

:include    => [{:children => [{:children => [:children, :upload]},
:upload]}, :upload, :tags])

Is that not absurd or what?  It's so far the only way I can avoid
queries during rendering.  Unfortunately that assumes the depth of the
tree, when in actuality it can be far greater.

Should I limit the depth of the tree?  This is for a discussion forum of
sorts. I don't know if it's typical to have potentially infinite tree
depth in threaded forums.

Should I even worry about pre-loading all data before rendering or just
go with the flow?  I'd like to cut down on the number of queries if
possible.
This topic is locked and can not be replied to.