-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Persistence
-
None
Given the following code:
person = Person.first person.name = "Different Name" Person.with(collection: 'other_people') { person.save! }
I would expect person.save! to raise a DocumentNotFound exception, because the record with the given _id does not exist in the other_people collection.
What actually happens is that the person.save! line simply fails silently. It raises no exception, but it also does not save the record.
The same behavior occurs with any sort of update when the record does not exist in the collection:
# updating directly to a different collection -- silently fails Person.with(collection: 'other_people') { person.update!(name: 'Different') } # deleting and then saving to the same collection person.name = 'Different' person.destroy person.save! # <-- silently fails person.reload # <-- raises exception because the record does not exist