已经提出了类似的问题
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
我想要做的是在其他几个表中包含类似的查询:
include [{:user => [:user_job_title, :user_departments], :group => []}]
当您搜索多个模型时,您会如何选择包含?
这是单一的例子:
Event.search(:include => [:user]) do...
答案 0 :(得分:4)
这个解决方案对我有用:
search_in = [Post, Tweet]
search = Sunspot.search search_in do
search_in.each{|m|data_accessor_for(m).include = [:user]}
[...]
end
希望这个解决方案有所帮助。
度过愉快的一天:)