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.
Activity
| Field | Original Value | New Value |
|---|---|---|
| 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 {code} doctrine orm:schema-tool:create --dump-sql {code} 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: {code} DELETE FROM PartialInvoice where dbID = '2'; {code} (PartialInvoice is the entity containing the above field declaration). It seems that the cascading delete feature is fundamentally broken. |
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. : {code} /** * @OneToMany(targetEntity="\persistentData\model\core\invoiceCreator\AnalogOrderInvoiceLineItem", mappedBy="partialInvoice", cascade={"persist", "remove", "detach"}) */ protected $analogOrderInvoiceLineItems; {code} 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 {code} doctrine orm:schema-tool:create --dump-sql {code} 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: {code} DELETE FROM PartialInvoice where dbID = '2'; {code} (PartialInvoice is the entity containing the above field declaration). It seems that the cascading delete feature is fundamentally broken. |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
| Resolution | Fixed [ 1 ] | |
| Status | Resolved [ 5 ] | Reopened [ 4 ] |
| Status | Reopened [ 4 ] | Resolved [ 5 ] |
| Resolution | Invalid [ 6 ] |
| Resolution | Invalid [ 6 ] | |
| Status | Resolved [ 5 ] | Reopened [ 4 ] |
| Affects Version/s | 2.1.1 [ 10153 ] | |
| Affects Version/s | 2.0.2 [ 10116 ] | |
| Environment | Debian Linux 5.0, MySQL 5.0 | Debian Linux 6.0, MySQL 5.0.51a |
| Component/s | ORM [ 10012 ] |
| Status | Reopened [ 4 ] | Resolved [ 5 ] |
| Fix Version/s | 2.1.1 [ 10153 ] | |
| Resolution | Invalid [ 6 ] |
| Workflow | jira [ 12528 ] | jira-feedback [ 14818 ] |
| Workflow | jira-feedback [ 14818 ] | jira-feedback2 [ 16682 ] |
| Workflow | jira-feedback2 [ 16682 ] | jira-feedback3 [ 18935 ] |
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1098, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
This is expected, cascade remove is working with in memory instances of the to be deleted objects. This way lifecycle events are triggered.
If you want to perform this operation on the databse level you have to set onDelete="CASCADE" as an option of the join column:
http://www.doctrine-project.org/docs/orm/2.0/en/reference/annotations-reference.html#annref-joincolumn
This difference should be explained in the docs on Working with Associations, 8.6 Transitive persistence / Cascade Operations i guess.