doctrine/DoctrineModule — pull request #96 by bakura10 (2012-10-04 20:30:20+00:00)
Title: Automate collection merging

Following my last changes : I added a Collection utils function that allow the user to automatically "intersect/union" elements from an old collection and a new one, so that the new elements of the new collection are added to the old one, and the ones removed from the new collection to be removed from the new collection too.

It "felt" bad to write the CollectionUtils::intersectionUnion in every entity method, so now it's completely automated and done in the hydrator (the test was quite a nightmare to write tbh).

So this :

```php
public function setSkills(ArrayCollection $skills)
{
foreach ($skills as $skill) {
$skill->setStudent($this);
}

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

return $this;
}
```

now become :

```php
public function setSkills(Collection $skills)
{
$this->skills = $skills;

foreach ($skills as $skill) {
$skill->setStudent($this);
}

return $this;
}
```

But as you can see there is one change : every method type-hinted has to be changed from ArrayCollection to Collection. The reason is because as the merge is done directly in the hydrator, it returns not an ArrayCollection but a Doctrine\ORM\PersistentCollection, so we have to typehint with Collection instead.

It is therefore a little BC, but as this CollectionUtils is really new, I think that it's worth it.

I'll change the doc to reflect those changes as soon as it is updated.