Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2677

Order_by criteria breaks Sum criteria (and other aggregations)

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None
    • None

      Consider the following

      def Table
        include Mongoid::Document
        field :name
        field :capacity
        default_scope order_by('name asc')
      end
      
      Table.sum(:capacity)            # this pukes an error
      Table.unscoped.sum(:capacity)   # this works
      

      I would propose that any order_by Criteria are removed/"switched-off" automatically by aggregation Criteria. Think Arel does this already.

            Assignee:
            Unassigned Unassigned
            Reporter:
            johnnyshields Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: