使用Rails 3.我有以下代码:
@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")
我无法在一个@reviews
中运行此查询,因为Country
有country_days
,但Shop
没有country_days
。如果我这样做:
@reviews = @user.reviews.includes(:user, :reviewable => [:photos, :country_days => [:shops => :photos]])
此代码不起作用,因为对于reviewable_type == "Shop"
,它没有country_days
。
如何将前两个查询组合在一起?