mirror of
https://github.com/doctrine/orm.git
synced 2026-04-26 16:08:03 +02:00
DDC-352: JOINED inheritance doesn't remove child object #436
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 (Feb 19, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user cloun:
I have a two class with joined inheritance:
I created PictureFile instance, added it to the Repository_Picture, flushed em. All worked fine. I saw in database one rows in the picture_ordered table and one in the picture_file table.
After that I tried to remove picture from Repository_Picture, and took the error: Integrity constraint violation
#0 E:...\library\Doctrine\DBAL\Connection.php(627): PDOStatement->execute(Array)
#1 E:...\library\Doctrine\DBAL\Connection.php(388): Doctrine\DBAL\Connection->executeUpdate('DELETE FROM pic...', Array)
#2 E:...\library\Doctrine\ORM\Persisters\JoinedSubclassPersister.php(283): Doctrine\DBAL\Connection->delete('picture_ordered', Array)
#3 E:...\library\Doctrine\ORM\UnitOfWork.php(785): Doctrine\ORM\Persisters\JoinedSubclassPersister->delete(Object(PictureFile))
#4 E:...\library\Doctrine\ORM\UnitOfWork.php(312): Doctrine\ORM\UnitOfWork->_executeDeletions(Object(Doctrine\ORM\Mapping\ClassMetadata))
#5 E:...\library\Doctrine\ORM\EntityManager.php(280): Doctrine\ORM\UnitOfWork->commit()
#6 E:...\application\models\Database.php(93): Doctrine\ORM\EntityManager->flush()
#7 E:...\tests\maksidom\PictureTest.php(28): Database::flush()
I think that problem is that Doctrine doesn't remove child (PictrueFile) object before removing parent (Pictrue) object.
@doctrinebot commented on GitHub (Feb 19, 2010):
Comment created by romanb:
Did you create the tables manually or through Doctrine? Does the picture_file table have a proper foreign key constraint to the parent table?
What does "SHOW CREATE TABLE picture_file" give you?
@doctrinebot commented on GitHub (Feb 20, 2010):
Comment created by cloun:
Here is a full error message: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
picture*file, CONSTRAINTpicture_file_pictureFOREIGN KEY (picture_id) REFERENCESpicture(picture*id))Strange question.. what is a 'proper foreign key'? If I take this error, it means, that table has restricted foreign key. All of FK in my DB is restricted, because cascade deletion is a BL logic (imho).
Here is DDL:
@doctrinebot commented on GitHub (Feb 20, 2010):
Comment created by cloun:
I have found out what the root of the problem. Doctrine checks whether database supported cascade deletion or not, and if it supported, then it removes only root entity.. May be with inheritance in database the principle 'restrict FK's' is not fit. I agree with your, constraint is not proper =)
But also I found another issue: if PK of child table will be not equal with PK of parent table, I think, this code will not work properly:
because $id contains PK of child table, but deletion executes from parent table.
@doctrinebot commented on GitHub (Feb 20, 2010):
Comment created by cloun:
Perhaps it would be useful to document this specific requirement (I tell about constraint with cascade deletion)?
@doctrinebot commented on GitHub (Feb 20, 2010):
Comment created by romanb:
Yes this should probably be better documented.
One question though: Did you create the schema manually or through Doctrine? Because if it was through Doctrine there might be a bug. Doctrine should create the proper foreign keys with ON DELETE CASCADE.
As you correctly found out, in the presence of foreign key constraints Doctrine only deletes the root row and lets the database delete cascade do the rest. This is the most efficient.
If you create the database schema not through Doctrine, you must ensure that the foreign keys are properly set up with ON DELETE CASCADE. That should be added to the documentation.
@doctrinebot commented on GitHub (Feb 23, 2010):
Comment created by cloun:
Not, I created schema manually (through design toolkit).
@doctrinebot commented on GitHub (Feb 23, 2010):
Comment created by @beberlei:
Is there are foreign key on the inheritance tables that has a ON DELETE CASCADE property? If not there is the issue :-)
@doctrinebot commented on GitHub (Feb 23, 2010):
Comment created by romanb:
@Benjamin: You can see in an earlier comment from Valery that ON DELETE CASCADE is indeed missing.
This is a documentation issue then.
@doctrinebot commented on GitHub (Feb 26, 2010):
Comment created by @beberlei:
Documented and closed
@doctrinebot commented on GitHub (Feb 26, 2010):
Issue was closed with resolution "Fixed"