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

Unable to access embedded fields in projected query results

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.4
    • Affects Version/s: 7.1.2
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      A change was made in Mongoid 7.1 that causes embedded fields accessors not to work on projected query results.

      For example, say you have a Person document with a Passport document embedded in the passport field. The following code raises an error:

      person = Person.only(:passport).first
      number = person.passport.number
      # ActiveModel::MissingAttributeError:
      #      Missing attribute: 'number'.
      

      Mongoid does not recognize the embedded field as one of the projected attributes.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            emily.giurleo@mongodb.com Emily Giurleo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: