Since version 6.7, Studio generates foreign key constraints with “on delete cascade” for hard-deleted entities, so your case should work. Could you check how the foreign key is defined in your database?
Here we should consider that sometimes there is a need to delete even soft-deleted entities, as well as linked by JOIN inheritance strategy ones. Let’s say an administrator is received a request to remove records which were created by mistake. Now this is not a piece of cake.
PS If I get it right, Keith wrote about FKs between tables used in JOIN inheritance strategy.
The “on delete cascade” exists on the EMPLOYEE table referencing the COMPANY table. But it does not exist on the FULL_TIME_EMPLOYEE table referencing the EMPLOYEE table. It seems that Studio allows setting up the cascade where Employee is an attribute of Company but it does not allow setting up the cascade where FullTimeEmployee extends Employee. So when I delete the Company, I think the framework is following through on the attempt to delete the EMPLOYEE row but breaks down because it is not deleting the FULL_TIME_EMPLOYEE row. To Ilia’s point, I am having trouble with the JOIN inheritance strategy.
From my perspective, the Employee to FullTimeEmployee relationship is one to one and deleting Employee should automatically result in deleting FullTimeEmployee, since they both represent the same employee.
Right now you can modify the foreign key generated by Studio in your Init data (30.create-db.sql) script like this:
alter table SAMPLE_FULL_TIME_EMPLOYEE drop constraint FK_SAMPLE_FULL_TIME_EMPLOYEE_ID^
alter table SAMPLE_FULL_TIME_EMPLOYEE add constraint FK_SAMPLE_FULL_TIME_EMPLOYEE_ID
foreign key (ID) references SAMPLE_EMPLOYEE(ID) on delete cascade^
I am currently using platform 7.4 and all my entities are hard delete.
I have set to CASCADE_DELETE option . I am still observing the issue.
I dont see DB scripts getting updated with “ON DELETE CASCADE”.
I am currently using the short term fix. I would like to check on which platform this fix is available
It’s fixed in Studio 6.9. Please do not confuse the platform and Studio versions. The former is a framework and the latter is a tool. This issue concerns only the tool (Studio) that generates DB scripts.
Please provide source code of your entity and the corresponding init scripts from Project > Data Stores > Main Data Store > init > 10.create-db.sql/20.create-db.sql
You have Document that extends StandardEntity. So the Document entity is soft-deleted.
Another point is that you set @OnDeleteInverse(DeletePolicy.CASCADE) to the One-To-Many attributes. Which doesn’t make sense.
For example if you want to delete all Documents when deleting Submission you need to set @OnDeleteInverse(DeletePolicy.CASCADE) on the submissionID attribute of the Document entity.
If both entities are hard-deleted, then foreign key with on delete CASCADE will be generated.
I would like to delete all the documents when deleting a submission, so setting a @OnDeleteInverse(DeletePolicy.CASCADE) on submissionID attribute of Document is sufficient ? I tried this and i dont see any update in the scripts.
Yes, setting a @OnDeleteInverse(DeletePolicy.CASCADE) on submissionID attribute of Document is sufficient.
As it was mentioned above you need both entities in relationship to be hard-deleted to set delete policy on database level. So you need to make the Document entity hard-deleted. Now it is not. Change the parent from StandardEntity to BaseUuidEntity and unselect SoftDelete checkbox.