Вопрос

I have a collection of Scorecards (where a user has scored a match)

I would like to sort their scorecards by the date the match was on (Which is stored in the match property)

The Scorecard and the Match are separate documents (not embedded) and would like to do something like the followed:

user.scorecard.sort(:match.dateofmatch).all

Where I have gone from the scorecard to its match object and to the match objects dateofmatch to sort. This isn't the correct syntax, How would I go about this? I am getting the feeling I will need to build my own model which is a scorecard with the dateofmatch property and once that is built, sort by it.

is this the case?

Это было полезно?

Решение

try sort_by

user.scorecards.sort_by{|sc| sc.match.dateofmatch }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top