-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 5.1.2
-
Component/s: None
-
None
emily.stolfo, I appreciate you fixing https://jira.mongodb.org/browse/MONGOID-3887.
Unfortunately, the approach as released in 5.1.2 breaks down when the query scope contains special operators such as Person.in(aliases: "foobar").first_or_create.
Mongoid would attempt to set the aliases field to {{ "$in" => ["foobar"] }} which of course is undesired. I have created to demonstrate the problem.
I am not sure what the best fix would be. I would suggest to either roll back MONGOID-3887 entirely – mongoid would then not support taking over Hash fields from the scope when using e.g. .first_or_create – or detecting special operators and ignoring them when dumping values into the new document. The latter would require great care to implement such that the issue doesn't recur when using nested operators or other oddities.
One could also merely document that fact that .first_or_create et al don't work as expected when confronted with special operators in the where clause but I would personally be against that "solution". Scopes might be passed around a lot before finally a .first_or_create gets appended and it would be difficult to ensure that the scope and final find or create call are compatible as they might be located in totally different parts of a codebase with the scope author not having taken into account that eventually a .first_or_create might be called on his scope.
Thoughts? I could take a stab at either solution if you were interested.
- is related to
-
MONGOID-3887 Criteria::Modifiable#create_document ignores Hashes
- Closed
- related to
-
RUBY-1092 Add option to check keys in BSON and provide configurable option in driver
- Closed