0

我正在尝试从数据库中获取总共 25 个关联。我希望 15 的计数等于 1,其余的计数大于 1(所以 10 大于 10)。我尝试了以下方法:

def self.get_specific_array
  a = Association.limit(25) # I would like a total of 25 associations
  a.where(["count = ?", 1]).limit(15) # I would like 15 of the associations to have a count of 1
  a.where(["count > ?", 1]) # I would like the remaining 10 associations to have a count that is greater then 1
  a
end
4

1 回答 1

2

您可以添加查询的结果数组:

a.where("count = 1").limit(15) + a.where("count > 1").limit(10)
于 2012-08-24T07:06:12.117 回答