Sunspot rails:在调用 .results 时包含相关模型 [英] Sunspot rails: include associated models when calling .results
本文介绍了Sunspot rails:在调用 .results 时包含相关模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我想在我的应用中搜索事件.例如,当我显示结果时,我想显示谁创建了事件.
Let's say that I want to search for Events in my app. When I display the results, I want to display who created the event, for instance.
有什么方法可以在某处添加 .includes(:user)
以避免不必要的查询(每个事件一个)?我在文档中找不到它.我应该只用事件索引用户名吗?但我必须让用户信息保持最新...
Is there any way to add .includes(:user)
somewhere, to avoid unnecessary queries (one for each event)? I can't find it in the doc.
Should I just index the user name with the event? But I'd have to keep the user info up to date...
谢谢
推荐答案
找到答案了,其实很简单:
Found the answer, it was actually quite simple:
Event.search(:include => [:user]) do...
这篇关于Sunspot rails:在调用 .results 时包含相关模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文