Lazy Loading and DB Query

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

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
information.

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

result.title
result.description
<author_name>result.author_name</author_name>

end

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

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
result.author_name.

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

Thanks.

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