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

Respect aliases in embedded documents when querying

    • Type: Icon: Improvement Improvement
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • 8.1.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

       

      Demonstration of issue:

      class Calendar
        include Mongoid::Document
      
        embeds_many :date_ranges, class_name: 'DateRange', store_as: :drs, cascade_callbacks: true
      end
      
      class DateRange
        include Mongoid::Document
      
        field :ed, as: :end_date, type: Date
      
        embedded_in :calendar, class_name: 'Calendar'
      end
      
      Calendar.where('date_ranges.end_date' => Date.parse('2022-01-01'))
      
      # EXPECTED
      Mongoid::Criteria
        selector: {"drs.ed"=>2022-01-01}
      
      # ACTUAL (broken -- unaliased)
      Mongoid::Criteria
        selector: {"date_ranges.end_date"=>2022-01-01}

       

      Oddly enough, these work correctly as of 7.4:

      MyNamespace::Calendar.pluck('date_ranges.end_date') #=> works
      MyNamespace::Calendar.distinct('date_ranges.end_date') #=> works

      Given that pluck/distinct work properly, it should be a high priority to fix aliases for all queries and get it into a 7.4.1 or 7.5 release.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None