Questions tagged «active-relation»

13
ActiveRecord查询联合
我已经使用Ruby on Rail的查询界面编写了一些复杂的查询(至少对我来说): 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对象。我想将这些帖子合并为一个ActiveRelation。由于某个时候可能有成千上万的帖子,因此需要在数据库级别完成。如果是MySQL查询,我可以简单地使用UNION运算符。有人知道我是否可以使用RoR的查询界面执行类似的操作吗?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.