Don't call sort! on ActiveRecord::Associations
The reason is sort! acts same as sort on ActiveRecord::Associations.
# Source code from ActiveRecord::Associations # The @target object is not \loaded until needed. For example, # # blog.posts.count # # is computed directly through SQL and does not trigger by itself the # instantiation of the actual post records.
I called sort! on a passed in parameter which is ActiveRecord::Associations and expect it acts like sort! on Array. This makes a bug of that method. I think rails is better to remove sort! from this class’s method list. NoMethodError is much better than this.