code: def sort(*ordering)
        resource = all
        ordering.compact!
        ordering.flatten!
        return resource if ordering.size == 0
        
        ordering.each do |order|
          order = Array(order)
  
          order.each do |column_or_relation, options|
            if column_or_relation.to_sym == :random
              resource = resource.random_sort
            elsif self.column_names.include?(column_or_relation.to_s)
              resource = resource.sort_for_column(column_or_relation, options)
            elsif reflect_on_association(column_or_relation.to_sym)
              resource = resource.select(resource.klass.arel_table[Arel::Nodes::SqlLiteral.new('*')])
              resource = resource.sort_for_relation(column_or_relation.to_sym, options)
            else
              raise ActiveRecord::StatementInvalid.new("Unkown column #{column_or_relation}")
            end
          end
        end
  
        resource
      end
docs: class << self
   ordering:
   :id
   :name, :id
   :id => :desc
   :id => {:desc => :nulls_last}
   :listings => :id
   :listings => {:id => {:asc => :nulls_first}}
   :random