Transactions and Cascade Deletes

I've been getting a lot of feedback since I started this RIAForge project from Sana Ullah. He's also been fairly interested in Transfer and while I've been absorbing the transfer documentation slowly, I haven't really followed Mark's blog. He directed me to this entry talking about nested transactions in response to an issue of related tables in the DataFaucet ActiveRecord object.

Thing is that until Sana suggested it, there hadn't been any support for join-subclass in DataFaucet. Or for that matter, the addManyToManyRelationship() feature was a new addition as well, I had been doing all that stuff manually before. Which introduced two new collections of potential update statements that might occur when you save the ActiveRecord. And they weren't bundled in a CFTRANSACTION, so if you were performing an update on a new record and it failed while inserting a related join-subclass table, you would end up with an orphaned record in the main table. So that meant the ActiveRecord object needed a transaction so it could roll back the update, but adding CFTRANSACTION in any OO codebase is problematic for reasons Mark mentioned in his blog entry.

So I created something probably reasonably similar to Mark's transaction object which allows the system to handle nested transactions. It's certainly not identical -- I didn't bother looking at any of Mark's code, I just wrote what seemed logical for DataFaucet.

Sana also pointed out that because he hadn't created a foreign key constraint (which I encourage you to always create) ;) the system wasn't deleting related join-subclass records (or many to many relationship records). So I've also updated the delete method to perform these additional deletes in the absence of a foreign key constraint. This one was never an issue for me personally because I always created a foreign key constraint so the system always deleted those for me automatically. I also added a transaction around the delete statement as well.

Changes have been committed to SVN plus documentation and I uploaded a new zip archive also.

I plan to update this project to Release Candidate status once I finish updating the onTap framework plugins to take advantage of some of the new features and am sure the automated form building / validation still works.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.5.006. | Protected by Akismet | Blog with WordPress