데이터베이스에서 총 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
1의 카운트 만 6이있는 경우 어떤 일이해야합니까? –
나머지는 1보다 큰 연관성으로 채워지고, 둘 다 5이면 10 개의 결과가 합계되어야합니다. 명확하게 해 주셔서 감사합니다. – Davinj
@Davinj 대답이 도움이 되었습니까? 그렇다면 그것을 받아 들일 수 있습니까? 감사! – joelparkerhenderson