Userwith a fieldnameと、 has_manyとteams、Teambelongs_to auserと belongs_to a があるとしsportます。ASportにはフィールドnameと has_manyがありteamsます。
をウォークスルーし、いくつかのことを行い、 の でソートされたのsports配列を収集したいと考えています。teamsnameuser
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リレーションの値でコレクションをソートする正しい方法は何ですか?