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 ]
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 ]