mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-1742: Cascade remove doesn't work with inheritance #2189
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Mar 30, 2012).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user toxygene:
When removing an entity with a one-to-many relationship with a cascade delete option on it causes a "Integrity constraint violation: 1451 Cannot delete or update a parent row:" error.
@doctrinebot commented on GitHub (Mar 30, 2012):
Comment created by toxygene:
I did some step debugging and it looked like the calculate commit order determined that the person should be removed before the animal.
@doctrinebot commented on GitHub (Mar 31, 2012):
Comment created by @beberlei:
It works for me.
See the testcase attached, you can put it into tests/Doctrine/Tests/ORM/Functional/Ticket, then run "phpunit --group DDC-1742" from the CLI to get the result.
Can you make it fail?
@doctrinebot commented on GitHub (Mar 31, 2012):
Comment created by toxygene:
I ran the provided test and could not reproduce the original error. There were some differences between the original environment and the environment I ran the tests in.
My original environment was a pear install of 2.2.1 and used the MySQL backend. The pear install does not include the unit tests, so I did a github checkout and used that source code for the tests. I initially got an error about not having pdo_sqlite installed, so I'm assuming the unit test used an sqlite(3) database for it's test. I can't imagine how either of these would effect the final result, but I wanted to note them, just in case.
Assuming neither of the previous differences is the source of the problem, I'll try to figure out how to reproduce the problem with a unit test today.
@doctrinebot commented on GitHub (Mar 31, 2012):
Comment created by toxygene:
Using the phpunit.xml file, I setup the unit tests to use MySQL instead of SQLite and I was able to reproduce the error:
jhendric@jhendric-Ubuntu:~/public_html/doctrine2-test/doctrine2-orm$ phpunit --group DDC-1742
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /home/jhendric/public_html/doctrine2-test/doctrine2-orm/phpunit.xml
E
Time: 1 second, Memory: 72.50Mb
There was 1 error:
Exception: [PDOException] SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
doctrine*tests.DDC1742Animal, CONSTRAINTFK_215064B57E3C61F9FOREIGN KEY (owner*id) REFERENCESDDC1742Person(id))With queries:
6. SQL: 'INSERT INTO DDC1742Animal (owner_id, type) VALUES (?, ?)' Params: '1', 'dog'
5. SQL: 'INSERT INTO DDC1742Person (id) VALUES (null)' Params:
4. SQL: 'ALTER TABLE DDC1742Animal ADD CONSTRAINT FK_215064B57E3C61F9 FOREIGN KEY (owner_id) REFERENCES DDC1742Person (id)' Params:
3. SQL: 'CREATE TABLE DDC1742Person (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB' Params:
2. SQL: 'CREATE TABLE DDC1742Animal (id INT AUTO_INCREMENT NOT NULL, owner_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, INDEX IDX_215064B57E3C61F9 (owner_id), PRIMARY KEY(id)) ENGINE = InnoDB' Params:
Trace:
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/lib/vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php:754
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/lib/vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php:438
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:464
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php:993
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/lib/Doctrine/ORM/UnitOfWork.php:331
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:355
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1742Test.php:38
/home/jhendric/public_html/doctrine2-test/doctrine2-orm/tests/Doctrine/Tests/OrmFunctionalTestCase.php:401
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
@doctrinebot commented on GitHub (Apr 1, 2012):
Comment created by @beberlei:
Ah yes, i have the same result I ran only against sqlite and they dont have foreign keys. Sorry for that.
@doctrinebot commented on GitHub (Apr 1, 2012):
Comment created by @beberlei:
Its not a bug, your mapping is wrong. The option is cascade={"remove"} not cascade={"delete"}
@doctrinebot commented on GitHub (Apr 1, 2012):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Dec 13, 2015):
Imported 1 attachments from Jira into https://gist.github.com/edd1d8dcc239343ca8d3