Imagine that I have a class Book, and a class Chapter, and Chapter has a
text attribute that contains the text of the chapter. Is there a
convenient railsy way to tell Chapter to only load chapter.text from the
db when/if it's specifically called for? For instance, if I'm using
@book.chapters to build a TOC, I'm not the least bit interested in the
chapter.text for all those chapters at this point, and am worried that
loading all that extra data will slow down the app. I'm wondering if I
can say something like...
class Chapter < ActiveRecord::Base
class Book < ActiveRecord::Base
has_many :chapters, :lazy_load => [ :text ]
But so far the only option I can think of is to offload the text to it's
own model ChapterText that belongs_to :chapter. I've been digging
through the API off and on for a couple weeks now hoping to stumble on
an elegant solution, but haven't yet. So, I'm thinking it's not
currently possible, except for using an extra model. Ideas?