在ActiveRecord中只使用一个条件加载多个表
问题描述:
published = Activity.all.eager_load([:podcast, :blog, :chat]).select('podcasts.draft = false')
我希望此代码输出所有不是草稿的播客,以及所有博客和聊天。相反,它会输出一切。在ActiveRecord中只使用一个条件加载多个表
答
使用where
如果要过滤未分组记录:
published = Activity.where('podcasts.draft = false').eager_load([:podcast, :blog, :chat])