When creating two related models and saving the main one to the database, both models get stored in the database. That is expected behavior. Now, when one of the two models has a validation problem and I call save() on it - without first linking it to the other model - I get a Doctrine_Validator_Exception. That is expected behavior. Now (patience, we're getting to the bug now), when one or both of the models has a validation problem and I link them prior to saving them, I don't get a Doctrine_Validator_Exception, but instead a database level exception Doctrine_Connection_Pgsql_Exception. That is unexpected behavior.
One wouldn't notice this issue when doing code like:
However, code like we are using it in our project more often looks like this:
In the attachment you find a test.yml and a test.php that I used for figuring out the behavior. Here's the output from running the test script:
Inspecting the Connection/UnitOfWork.php code, I see that saveGraph() calls $isValid = $this->insert($record). Now, when insert() sees that the record is invalid, it returns a false value. Somewhat later this results in calling $conn->transaction->addInvalid($record) to register the problem. At the end of the code block, I find (around line 126):
That is the point where things break. Even when an associated record does not validate, saveAssociations() will be called, resulting in a db level error about a reference id not being set (logical, since the related record was not saved and did not get an id assigned to it).
In my opinion, this shouldn't happen, but I'm only using Doctrine for one day, so if I am missing some important piece of knowledge or documentation here, then please let me know.