Sunspot rails: include associated models when calling .results

后端 未结 3 591
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 22:41

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.

Is there any way to add

相关标签:
3条回答
  • 2021-01-07 23:10

    This is an updated answer, if We need to include an nested association

    Then use this

    Event.search(:include => {:user => :city})
    

    In this case it will include user and his associated city

    0 讨论(0)
  • 2021-01-07 23:11

    Found the answer, it was actually quite simple:

    Event.search(:include => [:user]) do...
    
    0 讨论(0)
  • 2021-01-07 23:31

    Just in case you need to add a normal and nested include, here's what I needed:

    Professional.search(include: [:user, {branches: [:business]}]) do 
    
    0 讨论(0)
提交回复
热议问题