akeneo/pim-community-dev — pull request #1008 by gquemener (2014-04-09 13:49:13+00:00)
Title: Store and retrieve entities inside a document

Idea is to store in the document the ids of the entities and inject into the document property a lazy collection of entity.

# Working
## Lazy collection injection
Through the postLoad event, we read the current value of the field (the entity ids) and we inject into the property a ReferencedCollection instance configured with this ids.

## ChangeSet manipulation
Before updating the documents, we find the "entities" properties and replace the new value of the changeset (which is a ReferencedCollection) into an array of ids.

Ideally, the same should be done before inserting a document, but this is probably not the way to go, as the ChangeSet is empty (`$uow->getDocumentChangeSet($args->getDocument()) => []`). Solution, today is to override the actual field, but this is not ok as it means that we could potentially have access to an array of ids instead of a collection of entities when calling `Document::getEntities()` (which can be really confusing).

Another issue is that the changeset manipulation doesn't seem to work through `$args->setNewValue()` (that's why $uow->documentChangeSets is accessed publicly).