0

データベースから合計25の関連付けを取得しようとしています。15を1に等しいカウントにし、残りを1より大きいカウント(つまり、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 に答える