0

A similar question has already been asked

Sunspot rails: include associated models when calling .results

search = Sunspot.search(ArticlePost, Post, User, Group) do
   fulltext query
   with(:api_search_shared, true)
   paginate :page => page, :per_page => 100
end

what i want to do is include a few other tables with the query something like that:

include [{:user => [:user_job_title, :user_departments], :group => []}]

How would you go about go about putting the include in for when you are searching multiple models?

This is an example of a Single one:

Event.search(:include => [:user]) do...
Community
  • 1
  • 1
Jake McAllister
  • 1,037
  • 3
  • 12
  • 29
  • possible duplicate of [Sunspot rails: include associated models when calling .results](http://stackoverflow.com/questions/8282344/sunspot-rails-include-associated-models-when-calling-results) – fivedigit Aug 29 '14 at 22:12
  • Yeah in the question i say it similar. What i am asking is how to include it in the block – Jake McAllister Aug 30 '14 at 12:02

1 Answers1

4

this solution works for me :

search_in = [Post, Tweet]
search = Sunspot.search search_in do
    search_in.each{|m|data_accessor_for(m).include = [:user]}
    [...]
end

Hope this solution help.

Have a nice day :)

VictorTpo
  • 66
  • 3