Forum: Ruby on Rails Tire: Eager loading associations from multiple models

B6384f70845730889303cda976d4aa8d?d=identicon&s=25 arvinth s. (arvinth_s)
on 2013-12-17 08:03
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.
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2013-12-18 23:50
(Received via mailing list)
On Tuesday, 17 December 2013 02:03:47 UTC-5, Ruby-Forum.com User wrote:
>
>
> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.