doctrine/mongodb-odm — pull request #865 by jmikola (2014-04-30 21:06:49+00:00)
Title: Handle child classes that are unlisted in parent discriminator maps

Fixes #788, originally reported by @vmattila.

This PR adds tests for expected behavior when using discriminator maps with listed and unlisted classes. We test behaviors for top-level, embedded, and referenced documents. For embedded and referenced documents, we test inline discriminator maps (defined on the owning class) and external (defined on the embedded/referenced class) separately.

----

While implementing this, I contrasted our `DocumentPersister::load()` method with that of ORM's (in [`BasicEntityPersister`](https://github.com/doctrine/doctrine2/blob/7a305475e35930749e15bad0d060f8a917b1992f/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php)) and found that we inject discriminator criteria while ORM does not (according to [`getSelectSql()`](https://github.com/doctrine/doctrine2/blob/7a305475e35930749e15bad0d060f8a917b1992f/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php#L1012)).

In ODM, the criteria injection becomes problematic when the document we're loading by `_id` happens to not have a discriminator field at all, or it's field value is unlisted (e.g. it's a FQCN). One test that demonstrates this is looking up an unlisted child class by its own `_id` but using the parent class name (in the top-level document test). I currently expect `null`, but we could easily change this to find the actual document. Note that ProxyFactory ends up using the same code path (through `DocumentPersister::load()`), so a single fix here would "fix" the behavior for both top-level and referenced documents.