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

destroy embeds_one

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.5
    • Affects Version/s: None
    • Component/s: None
    • None

      Ive a simple class

      class Company
      embeds_one :location
      end

      Now when I set the location with a valid location everything works well - ie the doc is embedded

      c = Company.new
      c.location = Location.first
      c.save # Works well

      Now if I set the location to nil for an existing company it deletes the entire company - not the location
      c.location = nil # This deletes the company

      From the rails log
      MOPED: 127.0.0.1:27017 DELETE database=iaj32_development collection=companies selector=

      {"_id"=>"51e8c655aae103349900001d", "location._id"=>"51e23798aae10322fa005222"}

      flags=[:remove_first] (0.9406ms)

      c.reload # results in an error
      Mongoid::Errors::DocumentNotFound:
      Problem:
      Document(s) not found for class Company with id(s) 51e8c655aae103349900001d.

      I've tried this with the mongoid gems version 3.1.4, 3.1.2, 3.1.0 - but all cause the company to be deleted instead of deleting only the embedded location.

      Im running rails 3.2

      How do you delete an embeds_one ? embeds_many deletion works as expected.

            Assignee:
            Unassigned Unassigned
            Reporter:
            thimmaiah thimmaiah
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: