Lazy Loading and DB Query

Is there a way to combine lazy loading with a DB query using

Say I have two models, Books and Authors. And Books has the following:

acts_as_ferret :fields => { :title => { :index => :yes, :store => :no },
:description => { :index => :yes, :store =>
:no },
:author_name => { :index => :yes, :store =>
:yes } }

Let’s say that my Book model has a lot of attributes, and I don’t want
to store all these attributes for lazy loading. However, instead of
doing a join for the author name, I want to be able to lazy load the
author_name from the index while I do the query for the Book

When I perform the query I have Book.find_by_contents(“some query”,
:lazy => [:author_name])

and I print out the xml…

for result in @results



This gives me an error. I get an “undefined method author_name for

It ends up querying the “books” table which is what I expect. I even am
doing a @results.inspect and I can see that for each result, the
author_name has been loaded into the @data field for a FerretResult
while everything else belongs to the model that was retrieved from the
DB. However, I can’t access the author_name value by calling

How can I get that value out of the @data hash?


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