moving from trac, issue #2410 by zyxist
This ticket is related to the MySQL database and InnoDB engine with exporting all the information about the models (including foreign keys).
I have two tables connected with one-to-many relationship. First, I select a row from a "master" table with attached a field from the related "servant" row:
Next, I modify one of the columns in the master row and save everything:
Expected result: the master row is updated.
Actual result: MySQL error:
Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`doctrine`.`ticket_9999_master`, CONSTRAINT `ticket_9999_master_servant_id_ticket_9999_servant_id` FOREIGN KEY (`servant_id`) REFERENCES `ticket_9999_servant` (`id`))
If we remove "AS joe" part from the query, it gives the correct result. I noticed that with this alias, Doctrine forgets to retrieve the primary key of the servant row and this produces an invalid UPDATE query. There are two possible ways to retrieve this:
1. Use the data from the "Master" row, as we fetch everything, including the ID of the servant row. Doctrine knows about the relationship and potentially can use it.
2. Simply select the servant id automatically with the "s.bar" column.
Tested on software:
PHP 5.2.10, PHP 5.3.0
Doctrine 1.1-DEV (rev. 6217)