Affects Version/s: 1.0.12, 1.1.4, 1.2.0-ALPHA1
Fix Version/s: 1.2.0-BETA1
PHP Version 5.2.6-3ubuntu4.2, PHP Version 5.3
Doctrine Version 1.0.11 Revision: 6380
Doctrine Version 1.1.3 Revision: 6380
Doctrine Version 1.1.4 Revision: 6409
Doctrine Version 1.2
Linking between one to many relations with synchronizeWithArray() has a strange behavior.
Example (fully example is in the attachment):
Group has many Users
User has one Group
When I have a group-object (id 2) and do the following:
on the first execute of the script the users with id 1 and 2 are linked to group 2 (with foreign key = group_id in user table) -> right
on the second execute of the script the users with id 1 and 2 are linked to null -> failure
on the third execute of the script the users with id 1 and 2 are linked to group 2 -> right
on the fourth execute of the script the users with id 1 and 2 are linked to null -> failure
and so on
I tried to find the error on my self, but had no luck.
That's what I have found:
On every script-execution the relations to group 2 are first nulled.
If they were allready null für user 1 and 2, the relations are build with an update -> right!; but when this two users had allready this relation they are only nulled and no update is processed.
Thats why there is this strange toggling on the foreign key on every script execution.
Maybe it has something to do with the record_state which is clean, when the relations are allready set in the DB -> no update is executed, but the nulling of all foreign key linked to group 2.