Support for cascading deletes for DataObjects

106 views
Skip to first unread message

Erik Edlund

unread,
Dec 17, 2013, 4:02:15 PM12/17/13
to silverst...@googlegroups.com
Hello everybody!

It's been about two years since i tried to deal with the problem with cascading deletes for DataObjects in SilverStripe with the "janitor" module (https://github.com/redema/silverstripe-janitor). "janitor" was horrible and slow (it reimplemented referential actions in PHP in order to work with MyISAM) but it got the job done and it supported some nice features in the process.

Much has happened since "janitor" looked like a good idea and when I finally got a chance to start using SilverStripe 3.1 I took a look at "janitor" and got tired by just thinking of how much work it would require to update it to be SilverStripe 3 compatible.

So, instead I've created a brand new mess, which is a more "proper" implementation of referential actions for DataObjects. I took a wild guess that no one else is working on this as DataObject still have the comment about cascading deletes in DataObject.php (https://github.com/silverstripe/silverstripe-framework/blob/master/model/DataObject.php#L1357) and it has been quiet about the topic on this mailing list.

At the moment the implementation is part of larger module which is called patchwork, but there aren't that many files that one has to look at to get an idea of what I'm trying to do:

- https://github.com/redema/silverstripe-patchwork/blob/master/code/model/Constraint.php
- https://github.com/redema/silverstripe-patchwork/blob/master/code/model/PatchworkForeignKey.php
- https://github.com/redema/silverstripe-patchwork/blob/master/code/model/PatchworkMySQLDatabase.php

This implementation should probably be viewed as a proof of concept more than anything else, at the moment the code is a bit hacky (to put it mildly) since it must work around a couple of limitations in SilverStripe framework. Only the most basic features are in place:

- support for MySQL databases when the InnoDB-engine is used
- cascading deletes for child table rows when their parent row is deleted
- referential actions for has_one-relations
- support for Versioned DataObjects as long as they only use stages "Stage" and "Live" (note that it is not possible to create referential actions between Versioned and "ordinary" DataObjects - it seems practically impossible to support this in any sane way using only database constraints)

Feedback would be greatly appreciated if anyone finds the problem interesting and has some time to spare.

Reply all
Reply to author
Forward
0 new messages