结合多态包含条件

时间:2013-04-13 10:18:40

标签: ruby-on-rails polymorphic-associations

使用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中运行此查询,因为Countrycountry_days,但Shop没有country_days。如果我这样做:

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

此代码不起作用,因为对于reviewable_type == "Shop",它没有country_days

如何将前两个查询组合在一起?

0 个答案:

没有答案