<FromGitter>
<charleystran> what is the best way to sort an array of objects by a secondary relationship. I want to do something like game.players.sort{|a, b| a.rating.wins <=> b.ratings.wins } I think the null checking is beating me up
<FromGitter>
<Blacksmoke16> could you do that in the query
<FromGitter>
<charleystran> would I have to join first? if I do will it load the relation
<FromGitter>
<Blacksmoke16> whats nil in what you have now?
<FromGitter>
<charleystran> maybe I am wrong, and its a different problem. I am trying to sort the array and find if the item is in the top x positions and I get this `Error: undefined method '<=' for Nil (compile-time type is (Int32 | Nil))` for `players.sort{|a, b| a.wins<=> b.wins }.index(player) <= 2 ? 1 : 0`
<FromGitter>
<Blacksmoke16> nope looks like its possible for `.wins` to be nil
<FromGitter>
<Blacksmoke16> so you would have to handle that
<FromGitter>
<Blacksmoke16> by making sure they are no nil before doing your comparison
<FromGitter>
<Blacksmoke16> kinda makes me think would it make sense to have something in the stdlib to be able to handle that, id imagine it would just always be false vs compile error?
<FromGitter>
<charleystran> yea, I would love nil to never beat a real value in a compare
<FromGitter>
<charleystran> or if there was a way to default the value to 0, but I dont know know enough about crystal an amber yet
<FromGitter>
<Blacksmoke16> oh yea
<FromGitter>
<Blacksmoke16> `(a.wins || 0)`
<FromGitter>
<charleystran> so like `players.sort{|a, b| (a.wins || 0)<=> (b.wins ||0) }.index(player) <= 2 ? 1 : 0`