-
Type: Task
-
Resolution: Done
-
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=
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.