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

Embedded documents doubles on presence validation

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.1.1
    • Affects Version/s: 5.1.4
    • Component/s: None
    • None
    • Environment:
      Linux Mint 17.3
      Mongoid 5.1.4
      Mongodb 2.6.12

      When embed document have presence validation for parent document - it creates doubles on save.
      Example:

      class Person
        include Mongoid::Document
        field :name, type: String
        embeds_many :addresses
      end
      
      class Address
        include Mongoid::Document
        field :address, type: String
        embedded_in :person
        validates :person, presence: true
      end
      
      p = Person.create!(name: 'Person')
      p.addresses.build(address: '1')
      p.addresses.build(address: '2')
      p.addresses = p.addresses
      p.save!
      

      After save there are 3 addresses for person - 2 copies for the second one with same ObjectID

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            violarium Pavel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: