arvinth s.
2013-Dec-17 07:03 UTC
Tire: Problem with including associations while doing a multi-model search
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/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5608aedd6720d89e6b93cba39dafdffb%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Matt Jones
2013-Dec-18 22:48 UTC
Re: Tire: Problem with including associations while doing a multi-model search
On Tuesday, 17 December 2013 02:03:47 UTC-5, Ruby-Forum.com User wrote:> > 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''] > >This does not appear to be possible with the stock Tire gem: https://github.com/karmi/retire/issues/762 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8313b644-54ce-446f-9c92-c1417f2a6545%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.