doctrine/DoctrineModule — pull request #92 by bakura10 (2012-09-26 14:14:01+00:00)
Title: Utils to easier handling of updating

This completes my previous PR for hydrator.

This one adds a util function so that updating existing entities is simpler. Basically, the use case is the following :

1) A form create a bunch of elements in a collection.
2) Another form can edit those existing elements, and adding/removing new/old ones.

It was cumbersome to do before, now, in your setSomething function, it just becomes :

```php
public function setSkills(ArrayCollection $skills)
{
// do some specific work for maintening bi-directionnal
foreach ($skills as $skill) {
$skill->setStudent($this);
}

$this->skills = CollectionUtils::intersectUnion($this->skills, $skills);
```

The intersectUnion does two things : the first Collection is the "master" (the one that will be returned). First it removes all entities that are in the master array but are not in the new array (the second one). Secondly, it adds the new ones that were in the second array but not in the first.

If everything is ok I'll write tests ;-).

I would like, at some point, introduce it directly to the hydrator, so that calling this util function is not even needed in the entity code, but I didn't find a way yet.