XF 2.0 Downside to using cascadeDelete?

DragonByte Tech

Well-known member
I've recently discovered the cascadeDelete feature of entities, but I couldn't help but notice that it's almost never used in the core XF2 entities. According to a quick search with phpStorm, it's only used in AbstractNode and WarningDefinition entities. If I was to guess, I'd say the cascadeDelete function was added later in the development process of XF2, and it was deemed not worth the bother to go back and change old entities to cascadeDelete when _postDelete was already utilised?

From the comment in the User entity, I understand that using cascadeDelete can be dangerous if there's a chance the deletion could be interrupted, which I assume would likely be due to preDelete validation checks that could fail. For entities where there's no such preDelete checks, is there a downside?


Fillip
 
Significantly, you have no control over it, though there probably are more situations where we could use it. It's a straight sub-entity delete, whereas a lot of our scenarios intentionally do basic query deletes for more significant efficiency. There are also other places where we have some extra code that needs to be triggered (for example, changing behavior/entity configuration).

Equally, it's also not always totally clear that it's being triggered, so it could potentially cause debugging problems down the line (not that there aren't other things that do that).

If those limitations are acceptable, then it should be fine to use.
 
Thanks, Mike :)

The entities I'm applying this to will only ever be deleted via the AdminCP (or if I do add front-end controls, it'll be heavily restricted who or what can be deleted), and there'll be ample warnings with extra confirmation checkboxes if the system detects anything potentially critical that would be lost.
For instance; deleting a Product cascades to purchased Licences belonging to this product, but I would require a confirmation checkbox if the product had any purchased licenses associated with it.

In general, I want to discourage users from using the delete function anyway, so I think it should be fine to use cascades in this particular case.

I'm really loving working on XF2, the amount of advanced functionality I can implement with very little code is nothing short of amazing :D
It's easily the best software platform I've worked with, bar none.


Fillip
 
Back
Top Bottom