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

Setting an embeds_one to nil does not persist

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 7.0.1
    • 7.0.2
    • None
    • Ruby 2.5.1

    Description

      ++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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: