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

Order_by criteria breaks Sum criteria (and other aggregations)

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: