« [Article] Managing graphics in modules (and other thoughts) | Main | [tip] Add todo's to your code »
March 10, 2006
[Gotcha!] Cascading deletes
by David Workman
Data Mosaic
When this one happened to me the other day, I was pulling my hair out and swearing a drunk Gremlin (they are real you know and almost always drunk but only programmers know this) had crawled inside my solution before I could figure out what was going on. I was working on a solution that has quite a complicated data structure -- a couple of the forms show related data four levels deep ( table A --> table B --> table C --> table D). Even in Servoy, this kind of thing can twist your brain into knots to keep organized!
So in my already twisted brain state, I added a delete record script to one of the forms (a list view showing in a tab panel on the form for table A) based on a table somewhere below table A in the relationship chain. A simple thing under any circumstances one would think. But when I tested it...*poof*...the record I was on in table A disappeared! My own supernatural powers having recently been revoked due to unpaid parking tickets, I suspiciously looked around the room for the culprit.
Of course I ended up being the culprit...again. What got me this time?
| Posted by David Workman on March 10, 2006 at 09:10 AM in Gotcha! | Permalink
Comments
In your method, did you shift the "context" to the dependent file prior to deleting?
Posted by: Jim Schliestett | Mar 13, 2006 4:30:07 PM
Nope! Method right on the sub form containing only the delete function. I'll give this one a few more days....
Posted by: David Workman | Mar 13, 2006 7:38:00 PM
ANSWER
Say I had my delete method on Table C. Somewhere in the process of creating forms elsewhere based on table C I created a relationship from table C back to table A. A common enough thing to do to pull data in from other places.
What you don't want to do in this case is click the check box "Delete related records". This results in table C deleting a record in table A that it is referencing through the relationship when a record in table C is deleted.
In my case, table A shows a list of table C records. Delete one of the table C records and some long forgotton relationship from table C back to table A deletes the record in table A that I am on!
Quite stupid of me :)
Posted by: David Workman | Mar 15, 2006 1:37:31 PM