使用 Rails 3.2。我的模型以这样的方式嵌套:
- 评论 => 可评论(国家或商店)
- 国家 => CountryDay => 商店 => 照片
- 商店 => 照片
我有以下内容:
@reviews = @user.reviews.includes(:user, :reviewable)
通常我们可以通过这样的方式包含嵌套多态:
# this will return errors because :shop is not found in the model Shop (:reviewable is actually :shop)
@reviews = @user.reviews.includes(:user, :reviewable => [:shop])
# this will return errors because :photos is not directly associated to Country
@reviews = @user.reviews.includes(:user, :reviewable => :photos)
还有许多其他变体。如何解决它以使 ActiveRecord 包含基于其关联的正确模型?