Delete the rows referencing a comment before the comment - #245
Open
boo-code wants to merge 1 commit into
Open
Conversation
|
Hello @boo-code! This is your first pull request on productcomments repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
id_product_commentas aManyToOne- the database refuses the first statement withCannot delete or update a parent rowand the comment cannot be deleted from the back office. Removing the referencing rows before the comment works with or without the constraints.How to test
The constraints are the ones
doctrine:schema:update --dump-sqlproposes from this module's own entities, for example:With that constraint in place, on MySQL 8.4:
In the back office: with the constraints applied, deleting a comment from Catalog > Product comments fails before this change and succeeds after.
Why ordering rather than cascade
#199 proposed adding
onDelete="CASCADE"to the join columns. That works too, but it only takes effect once each shop regenerates its schema, so shops that already have the constraints keep failing until they do, and it leaves the manual deletes doing nothing.Reordering needs no schema change, no migration and no assumption about whether a given shop has the constraints at all: the rows are removed explicitly in both cases, and the parent goes last. Shops without the constraints are unaffected, since the same three statements run either way.