Affects Version/s: 1.2.3
Fix Version/s: None
Environment:PHP 5.2.10, MySQL database connection
I have continually run into a very particular bug when using OneToMany relationships between Doctrine tables. When attempting to call "link()" to generate a relationship between records in related tables, Doctrine attempts to set the ID of the "one" portion of the record to 0, then save it.
This is best demonstrated by the sample YML and PHP that I have attached. It establishes a OneToMany relationship where the "one" table has another foreign key constraint. This causes the DB to trigger a foreign key constraint error when Doctrine tries to set the ID to 0, making the error easier to see.
From looking into the relevant sections of the codebase, the following appears to be happening:
- Calling "link" properly adds the relationship to the "many" record.
- Calling "save" triggers the saving of the "many" record and all associated records.
- With the "one" record now listed as an associated record, its own "save" function is called as a result.
- Its "save" function works properly, except that for some reason, the ID key is not present in the $_data internal array (but oddly is present in the $_id array, allowing it to be returned in other places).
- Seeing a difference, Doctrine attempts to execute an "UPDATE" query setting the ID to 0.
I've made it this far in looking into it, but for the life of me I can't figure out what is triggering the identifier being reset in this case. I should note, however, that it happens consistently in every such situation on every server I've tested it on.