Tire: Problem with including associations while doing a multi-model search

30 views
Skip to first unread message

arvinth s.

unread,
Dec 17, 2013, 2:03:47 AM12/17/13
to rubyonra...@googlegroups.com
I am using elasticsearch for querying in my application. Lets say there
are 2 models

Class Topic
has_many :posts
and

Class Article
has_many :comments

I want to do a combined search on both these models and my query looks
like:

Tire.search [Article, Topic], {:load => {:include => [:posts,
:comments]}} do |search|
...
end
This is where I encounter a problem. I get the

Association named comments not found

error. I think this is because Topic model doesn't have the association
comments and I think the same thing will happen for posts with the
Article model.

Is there anyway to solve this problem? I was thinking maybe something
like

:include => ['topic.posts', 'article.comments']

Please help me out.

--
Posted via http://www.ruby-forum.com/.

Matt Jones

unread,
Dec 18, 2013, 5:48:48 PM12/18/13
to rubyonra...@googlegroups.com
This does not appear to be possible with the stock Tire gem:


You may want to try applying the changes in that issue. Your example would look like:

 Tire.search [Article, Topic], {:load => { Article =>{ :include => :comments}, Topic => { :include => :posts } } }  do |search| 

--Matt Jones
Reply all
Reply to author
Forward
0 new messages