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

Setting an embeds_one to nil does not persist

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.2
    • Affects Version/s: 7.0.1
    • Component/s: None
    • Environment:
      Ruby 2.5.1

      ++Setting an embeds_one to nil does not persist.

      For example:

      Mongoid::VERSION # => "7.0.1"
      
      class A
        include Mongoid::Document
        embeds_one :b
      end
      
      class B
        include Mongoid::Document
        embedded_in :a
        field :memo, type: String
      end
      
      a = A.create(b: { memo: 'before' })
      a.b.memo # => "before"
      
      a.b = nil
      a.b # => nil
      
      a.save
      a.reload
      
      # I expect it to be nil
      a.b # => #<B _id: 5b33301f13909416dbc0d480, memo: "before">
      

      It works well in version 6.2.1.

      In version 7.0.1 it works well when calling destroy method.

      Thanks

            Assignee:
            sam.rossi@mongodb.com Samuel Rossi (Inactive)
            Reporter:
            ktanaka777 Kentaro Tanaka
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: