2 Replies Latest reply on Aug 16, 2016 2:22 PM by JaredHague

    Weak reference with relationships?


      So its easy enough to delete a child record when then parent record is deleted. 


      Im wondering if anyone has come up with a way to delete a parent record when the last child is deleted?  Right now I am resorting to a script that looks for parent records that have no child. Has anyone thought of a way to do this automatically? 

        • 1. Re: Weak reference with relationships?

          not automatically, as you're editing... I'd imagine this could be dangerous. What if you are removing the last record in order to add another one?


          The best I could imagine is to have a calc field on the parent that checks if there are related records, then runa script that searches for these records, delete (or better still, archive) the records that don't have children.


          You could schedule the script run run on server, if you really wanted.

          • 2. Re: Weak reference with relationships?

            Its not an dangerous as you might think.  Its very common in other programming to enable garbage collection.


            In the case you are stating as an example you would definitely need to add a record before removing the last one.  The whole idea is the parent record is irrelevant when it doesn't have any child records. Its really more of a backwards way of looking at things because the "Parent" name makes you assume that is the master record or the record you would be working from.  All this "Parent" table would be doing is grouping records together with some additional data.  When there is no items in the group it doesn't need to exist.


            Anyway its more a memory management issue so a script would probably be fine although automatic would be much cleaner.