-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cascade delete for relations #3193
Comments
In the case of |
I've just created a new card on our public roadmap, please share your insights even if this feature is pretty easy to understand (https://portal.productboard.com/strapi/c/59-cascade-delete). |
Any news on this? Now that Strapi has removed support for mongodb, supporting pure relational feature should be a priority. |
you can check the roadmap here and vote for this feature, which is currently in "Under Consideration" tab |
While it won't be the default in v4, since we will be creating all of the foreign keys by default for relations there will be a way to modify these foreign keys with a cascade delete option. We will provide more information after the v4 is released and we can test these new features. |
How does the cascade delete work in v4? I found nothing in the documentation. |
@ludi81 no changes there, you have to manually declare cascade logic writing a code in lifecycles.js |
In the future you'll be able to tweak the foreign key logic to handle cascade delete at the database layer. It's not supported yet nor documented but it's something we are working on. |
@derrickmehaffy any updates on this? @lnikell any tips how to do this in v4? I used to do it with the |
Not at this time, we will need to add some advanced custom support to allow modification of the foreign keys which we don't currently have yet. I'll reopen the feature request though |
Same need here, especially since there is no way to filter on components (so forced to switch on a dedicated collection with the drawback of orphan in database while deleting the parent). Personally, I will not do it at code level because it's a database feature/responsibility. Despite a proper implementation in strapi could take time, writing a simple documentation to achieve the same effect by modifying the foreign key looks like a good workaround. wdyt @derrickmehaffy ? EDIT: something like this for example: https://stackoverflow.com/a/14381227 |
In the v4 you can filter on components just not dynamic zones |
Even using graphql? 🤔 As you can seen there is nothing about my |
For anyone else trying to achieve that, I finally use a mysql trigger like this: CREATE DEFINER=`somedatabase`@`%` TRIGGER delete_orphan_contacts_details
BEFORE DELETE
ON prospects FOR EACH ROW
BEGIN
SET @contact_details_ids := (SELECT GROUP_CONCAT(contact_details_id) FROM prospects_contacts_details_links WHERE prospect_id = OLD.id);
DELETE FROM prospects_contacts_details_links WHERE FIND_IN_SET(contact_details_id, @contact_details_ids);
DELETE FROM contacts_details WHERE FIND_IN_SET(id, @contact_details_ids);
END In my case the relationship is "prospect has many contactDetails". Explanation:
Hope it could help others... NB: if someone found a better way (at DB level), don't hesitate: tell me! 😜 |
Hey all, we are currently moving many feature requests to our new feedback and feature request website to help clean up the GitHub issues and make it easier for us to review bug reports and fix them. I have moved this feature to the following URL: https://feedback.strapi.io/feature-requests/p/allow-customization-of-foreign-keys-for-options-like-cascade-delete For now I will close this and lock it so that all new information goes into our new feedback website. |
Hello.
I'd like to avoid orphan contens by using a
cascade
attribute to therelation
field type.Cheers,
Steve
The text was updated successfully, but these errors were encountered: