propelorm/Propel — pull request #286 by willdurand (2012-02-11 20:00:17+00:00)
Title: [Generator] Fixed collection setter with existing objects in a N-N relation

**This PR needs unit tests** but I created it to get feedbacks.

In order to detect a modification by reference, we compare the internal
collection with the given collection. If an object is new (in the given
collection), we add it by calling `doAdd*()`, instead of `add*()`
(forcing). It works fine with new objects (`isNew()` returns `true`).

In the case where the given collection contains existing objects, we
call the `add*()` method. This method determines whether to insert
the object or not by calling `contains()` on its internal collection.

But it never takes care of association objects in a N-N relation. That
means, you can add existing objects by reference, they will appear in
the internal collection so it won't re-add them, but it will never
create association objects, and it won't modify the internal collection
for these association objects.

The fix here is to look into the collection of the given object you want
to add in the `add*()` method. If this object has `$this` (the main
object) in its collection, you won't add it twice. But, in case it doesn't
have this main object, it will add the given object, and then it will create
a new "association" object by calling `doAdd*()` (forcing).

The last thing is to not re-add the given object in the internal
collection (case: the collection has been modified by reference).