Best approach for sorting by relationship count

I also am curious to know what solution you came up with, @miquelromero.