【发布时间】:2014-10-19 14:57:20
【问题描述】:
我需要创建一种演绎查询,其中相同的记录被多次排序,并且每次的排序都独立于之前的订单执行。
如:
tallest_trees = Trees.order(:height => :desc).limit(10) # Gets 10 of the tallest trees out of all available trees
tallest_trees.order(:width => :desc) # From the 10 of the tallest trees, gets the widest trees **without** any regard to their height
我尝试以与上述类似的方式进行操作,但结果始终是它尝试在本例中按高度和宽度对树木都进行排序同时,这与我的需求相反。
在直接使用 ActiveRecord 或 SQL 方面没有任何区别。我相信答案是我必须以某种方式“稳定”上一个查询,以便第二个查询不仅继续它,而且重新排序。
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-4