remove filter criteria from query as it is handled in the DocumentPersister
prepare collection/filter queries
DocumentPersister::prepareQueryOrNewObj() method is now used instead of DocumentPersister::prepareSubQuery().

DocumentPersister::convertTypes() was removed and now PHP type to database value conversion happens in the same query iteration in the DocumentPersister::prepareQueryOrNewObj().
Regression test for reference-many collections and filter criteria

This verifies injection of filter criteria into owning and inverse sides of reference-many collections.

The behavior for owning sides is not ideal, due to how proxies are handled. On a side note, sort/limit/skip/criteria support for owning side collections is also odd and should probably be removed. Criteria support for (persistent) collections, when implemented, will be a more viable alternative.

See: #593
$unset empty array collections or null embed many field values.

closes #597
Rename DocumentPersister::prepareSort() to prepareSortOrProjection()
unset when new value is null only
added test case for ReferenceMany mapping
Do not unset EmbedMany fields in PersistenceBuilder

If an EmbedMany collection field is set to null, the original PersistentCollection is scheduled for deletion in UnitOfWork::computeOrRecomputeChangeSet(). Unsetting it in PersistenceBuilder would lead to a duplicate $unset query.
Merge pull request #598
Add filter/discriminator criteria at Query-level, not Expr (fixes #596)

Break up methods to inject filter criteria and discriminators into prepared queries. This is now done at the query builder level, instead of expressions, as it is only relevant for the top-most query array. These methods are also used by the DocumentPersister's load/loadAll() methods.

prepareNewObj() was renamed to prepareQueryOrNewObj(), since it is used by the Expr class and DocumentPersister's own load/loadAll() methods.

DocumentPersister::load() was the only method whose $criteria was not always an array, so scalar/MongoId conversion was moved within. Support for null $criteria was removed, as no code paths would provide such a value.
Merge pull request #599 from doctrine/gh596

Add filter/discriminator criteria at Query-level, not Expr
Added a test case for GitHub issue #560
Refactor test for #560 to use an event subscriber
Dispatch postPersist callbacks/events for upserted documents (fixes #560)

Previously postPersist lifecycle callbacks and events were only dispatched (and cascaded) for documents that were batch inserted (i.e. documents whose ID needed to be generated). This change splits up the post-insert processing (essentially the inline registerManaged() call) and event dispatching, so that upserted documents are always handled.

Additionally, DocumentPersister::executeInserts() was changed to always return an array, even if no documents were scheduled. This is consistent with its documentation and shaves some code from the calling context.
Refactor UnitOfWork::cascadePostPersist()

Some object calisthenic improvements.
Optimize class lookups if mapping has targetDocument defined

This should prevent unnecessary DocumentManager::getClassMetadata() lookups for most cases.
Merge pull request #601 from doctrine/gh560

Dispatch postPersist callbacks/events for upserted documents
Improve regression test for #593 to check proxy state

Checking if the proxy is initialized and manually loading it is a more accurate test for hydration behavior in DocumentPersister::loadReferenceManyCollectionOwningSide().
Use target class' DocumentPersister when preparing referenceMany criteria

Closes #602