Its a good idea to always sort by string in this method.
I suggest:
associations.all.sort_by { |as| as.to_s }
It works well for hostgroups too (because of the to_s implementation of hostgroups).