2013-11-15 1 views
0

다음 기능은 활성 레코드 평판 시스템 link to gem을 사용하여 비즈니스 (관계)를 내림차순으로 정렬합니다.find_with_reputation에 대한 여러 개의 주문 값

@businesses = Business.find_with_reputation(:votes, :all, order: "votes desc") 
(오래된 상단)이 투표에 의해 정렬 그래서 내가 두 번째 순서 값을 추가하지만 투표가 동일한 경우는 created_at으로 정렬 할 방법

?

단순히인가 :

@businesses = Business.find_with_reputation(:votes, :all, order: "votes desc, created_at desc") 
+0

"find_with_reputation"이 어떤 단서를 가지고 있긴하지만 올바른 것으로 보입니다. – Zippie

답변

1

난 당신의 제안 대답은 'created_at은'아마 명성 테이블과 비즈니스 테이블 모두에서 발생하기 때문에 SQL 오류가 발생할 것입니다 용의자. 이 문제를 해결하기 위해서는 created_at에 대해 구체적으로 제안하는 것이 좋습니다.

Business.find_with_reputation(:votes, :all, order: "votes desc, businesses.created_at desc") 

그러나 대신 id 열을 사용하는 것이 좋습니다. INTs를 사용하면 DB가 더 빨라지고 정렬 순서가 동일해야합니다.

Business.find_with_reputation(:votes, :all, order: "votes desc, businesses.id desc") 
+0

답변 해 주셔서 감사합니다. 나는 그것을 시도 할 것이다. – grabury