2

Using Rails 3. I have the following code:

@reviews = @user.reviews.includes(:user, :reviewable => :photos).where(:reviewable_type => "Shop")
@reviews = @user.reviews.includes(:user, :reviewable => :country_days => [:shops => :photos]).where(:reviewable_type => "Country")

I can't run this query in a single @reviews because Country has country_days, but Shop doesn't have country_days. If I do this:

@reviews = @user.reviews.includes(:user, :reviewable => [:photos, :country_days => [:shops => :photos]])

This code won't work because for reviewable_type == "Shop", it doesn't have country_days.

How can I combine the first 2 queries together?

4

0 回答 0