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

Using 'without' breaks access to attributes of embedded documents

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 7.3.1
    • Affects Version/s: 7.3.0
    • Component/s: None
    • None
    • Fully Compatible

      Hi!

      Given the following models:

      class User
        include Mongoid::Document
      
        field :email, type: String
        embeds_one :profile, class_name: 'Profile'
      end
      
      class Profile
        include Mongoid::Document
      
        field :bio, type: String
      end
      

      Calling this will work

      User.last.profile.bio
      #=> "This is a bio"
      {code:ruby}
      
      but calling this will fail
      
      {code:ruby}
      User.whitout(:email).last.profile.bio
      #=> ActiveModel::MissingAttributeError: Missing attribute: 'bio'
      

      Is this the expected behavior or a bug? It worked with mongoid v6 but no longer does in v7.

      Thanks

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            simon@textmaster.com Simon Courtois
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: