We have 2 Primary tables with 3 different types of items:
In primary table Shipping_Pkgs we have a "Shipping_Manifest" type item and a "Manifest_Line" type item. In the 2nd primary table (Envelopes) we have Envelope type items.
The user creates a new Shipping Manifest. In the following description, assume that the "current item" is a Shipping Manifest. In the "Add Envelopes" transition the user selects Envelope items to be added to the Shipping Manifest. We have scripts that run that create a Manifest Line record for each Envelope selected by the user. We associate that Manifest Line with the Shipping Manifest via a single-rel field. The script then associates the selected Envelope to the Manifest Line item created by the script, and the Manifest Line back to the Envelope via a pair of single-relational fields. The Shipping Manifest is associated to the Manifest Line via a multi-relational field because a user wants to ship multiple Envelopes in a single Shipping Manifest. All-in-all we have 3 single-relational fields and 1 multi-relational field to track these relationships.
The users know about Envelopes and Shipping Manifests, but not about Manifest Line items .... the "Manifiest Line" is just a way to relate a Shipping Manifest to one or more Envelopes. The embedded reports that the user sees displays the Manifest Lines on the Shipping Manifest but it shows Envelope information (via sub-relational fields). The user thinks they're seeing Envelopes.
So:
- A Shipping Manifest can have 0 or more Manifest Lines items. The related Manifest Line items are in a Multi-Relational field "Manifest Lines" (note plural).
- A Manifest Line item is created by scripts whenever a user wants to add an Envelope to their Shipping Manifest.
- The Envelope item points to the Manifest Line item with the "Manifest Line" (note singular) single-relational field. The Manifest Line item points back to that same Envelope with the "Envelope" single-relational field.
- The Manifest Line item is related to it's "parent" Shipping Manifest via the "Manifest" single-relational field.
Let's say we want to "remove" an Envelope from the Shipping Manifest. Currently our scripts are doing all the work of deleting the Manifest Line item, clearing up the Envelope's "Manifest Line" field, removing the ID of the deleted Manifest Line item from the Shipping Manifest's "Manifest Lines" field.
I was thinking ... what if our scripts just delete the Manifest Line item?? I think if I manually delete a Manifest Line item in the GUI (with the Delete transition), SBM will find all the references to the deleted Manifest Line record and remove those. Is that right?? I'm willing to bet that deleting the Manifest Line record via the AppRecord "Delete" method might do the same thing. Does it? And if so, is it faster to let SBM clean up all the references to the deleted item, or are we better off continuing to do it ourselves in the AppScripts?
Now for some obscure extra-points questions:
Will SBM clean up everything and delete the Manifest Line record if we only modify only one of the single or multi relational fields??? I.e. will SBM do all that work if we just do one of the following:
- Remove the ID of the Manifest Line to be deleted from the Shipping Manifest's "Manifest Lines" multi-relational field (disassociating the Manifest Line from the Shipping Manifest)?
- Clear the Manifest Line's "Manifest" single-relational field (disassociating the Shipping Manifest from the Manifest Line)??
- Clear the Manifest Line's "Envelope" single-relational field (disassociating the Envelope from the Manifest Line)??
- Clear the Envelope's "Manifest Line" single-relational (disassociating the Manifest Line from the Envelope)???
My guess is "no" to any of those.