Tag: activerelation

ActiveRecord查询联盟

我用Ruby on Rail的查询界面写了一些复杂的查询(至less对我来说): watched_news_posts = Post.joins(:news => :watched).where(:watched => {:user_id => id}) watched_topic_posts = Post.joins(:post_topic_relationships => {:topic => :watched}).where(:watched => {:user_id => id}) 这两个查询都可以自行工作。 两个都返回Post对象。 我想将这些post合并成一个ActiveRelation。 由于在某个时候可能会有数十万个职位,因此需要在数据库层面进行。 如果它是一个MySQL查询,我可以简单地使用UNION运算符。 有谁知道我能否用RoR的查询界面做类似的事情?