When a default_scope exists on either side of a many-to-many relation that applies options (like a sort), the resulting MongoDB command to update the keys is invalid since MongoDB doesn't like $and queries inside an update with a $query and $orderby options. It raises no error in safe mode, but does log the following error in the db: exception: invalid operator: $and code:10068 0ms This fix removes any options in the criteria when updating the keys. [ fix #2280 ]
If a selector existed as a scope, and it had a nil value in it, the scope would get cleared completely since we checked only for nil and not if the key existed. [ fix #2272 ]
In order to guard from models attempting to pull a document from the identity map that matches the id, but is of a type that is a parent or sibling, we need to add the type selection to the check as well. [ fix #2259 ]
…oped directly. DRYing up duplicate code.
…g for count > 0 since Mongo does not use counted b-tree indexes. C.f., https://jira.mongodb.org/browse/SERVER-1752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=147517#comment-147517
- Previously the persistence options would be cleared out after the database query that the uniqueness validation performs, causing the document to be persisted in its normal location. This now keeps the options in the thread local unless validation fails. - [ fix #2234 ]