의 내가 필드 name
, 어느 has_many teams
와 User
및 user
을 belongs_to Team
및 sport
belongs_to 있다고 가정 해 봅시다. Sport
에는 name
필드와 has_many teams
필드가 있습니다.Mongoid를 사용하여 중첩 된 필드 값별로 정렬하는 방법은 무엇입니까?
가 나는 sports
을 통해 걸어 몇 가지 물건을하고 user
의 name
으로 정렬 된 teams
의 배열을 수집 할.
result = []
Sport.asc(:name).each do |spt|
# some other stuff not relevant to this question but that
# justifies my looping through each sport.
spt.teams.asc(:'user.name').each { |t| result << t }
end
이 있지만 실행하고 sports
의 정렬이 예상되는 한,하지만 예상대로 result
에서 팀의 순서는 정렬되지 않습니다.
Mongoid
을 사용하여 관계 값으로 모음을 정렬하는 올바른 방법은 무엇입니까?