Details
Description
The console tools do not generate the proper DDL statements for the constraints declared as part of the relationship annotations.
Take this entity field declaration, e.g. :
/** * @OneToMany(targetEntity="\persistentData\model\core\invoiceCreator\AnalogOrderInvoiceLineItem", mappedBy="partialInvoice", cascade={"persist", "remove", "detach"}) */ protected $analogOrderInvoiceLineItems;
This declaration should generate some sort of ON DELETE CASCADE constraint, or at least actually cascade the delete, in whatever way. It does not. I reviewed the generated DDL statements with
doctrine orm:schema-tool:create --dump-sql
And it clearly showed that no "ON DELETE CASCADE" was generated. Neither did Doctrine 2 perform a cascading delete otherwise.
The delete simply does not cascade.
Subsequently, I end up getting errors like:
Exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails
(`invoiceCreatorDB/AnalogOrderInvoiceLineItem`, CONSTRAINT `AnalogOrderInvoiceLineItem_ibfk_1` FOREIGN KEY (`partialInvoice_dbID`) REFERENCES `PartialInvoice` (`dbID`))'
The query that caused the error is:
DELETE FROM PartialInvoice where dbID = '2';
(PartialInvoice is the entity containing the above field declaration).
It seems that the cascading delete feature is fundamentally broken.