You might want to try removing the @ symbol from comments and name it
something else to avoid conflict with your relationship.

def post_comments
  self.comments.inject([]) { |ary, c| ary << c.body << c.name }.join(' ')
end

-Lee

On 7/21/06, Rami Bitar <[EMAIL PROTECTED]> wrote:
> Using Ferret and the acts_as_ferret plugin, I would like to retrieve
> results based on models descended from a parent model:
>
> class Post < ActiveRecord::Base
>
>     acts_as_ferret :fields => [ 'title',
>                                 'body',
>                                 :post_author,
>                                 :post_comments
>                                 ]
>    ...
>
>    has_one  :author
>    has_many :comments
> end
>
> I would like to search all comments of a post and retrieve Post models
> as search results.  Currently, searching across :author fields is
> achieved using:
>
> def post_author
>     self.author.name
> end
>
> However, a similiar technique does not seem to work for the has_many
> relationship:
>
> def post_comments
>     for comment in self.comments
>         @comments << comment.body
>         @comments << comment.name
>     end
>     @comments.join(" ")
> end
>
> Searching across author fields finds the correct Post.  However, none of
> the comments seems to be indexed and/or associated with the correct Post
> so no search results are found.  I would appreciate any help on this.
>
> Thanks!
>
> Rami
>
> --------
> Note: The post model is saved after comment changes are made in order
> for acts_as_ferret to index the Post.  Also note that multi_search would
> not easily apply here since I know for certain I would like to retrieve
> the Post model, and not the Comment or Author model as search results.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk
>
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to