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

Error when reloading with a nil embedded field

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

      We get an error with the following code: 

      class Band
        include Mongoid::Document
        embeds_one :label
      end
      class Label
        include Mongoid::Document
        field :name, type: String
        embedded_in :band
      end
      
      label = Label.new(name: "Neil")
      b = Band.new(label: label)
      b.save!
      b.label = nil
      label.reload  # error 

      This spawns the following error:

      `reload': undefined method `empty?' for nil:NilClass (NoMethodError) 

      Which seems incorrect. I think an error should still be raised in this case, but a more appropriate one with a more descriptive message.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: