[Lazarus] [OT] How to delete a record/object being used

Michael Van Canneyt michael at freepascal.org
Tue Sep 9 17:06:49 CEST 2008



On Tue, 9 Sep 2008, Graeme Geldenhuys wrote:

> On 9/9/08, Michael Van Canneyt <michael at freepascal.org> wrote:
> >
> > Not if all foreign keys to the table have the cascade delete option specified,
> >  then it is automatic. This is the option I most of the time use.
> 
> Thanks for the response.  After I sent the message, I thought this
> might be an option as well. Thought I have never used it, it sounds
> dangerous. :-)
> 
> 
> >  When you delete AdresType record with ID 1, all ADDRESSES records that have
> >  AddressType =1 will automatically be deleted.
> 
> OK, now the big question which might affect you as well.  How do you
> translate this to tiOPF based applications?  What if you delete an
> AddressType from the database (with cascade delete), but still have
> some objects (Contacts) in memory. They wouldn't know about the
> cascade delete. In tiOPF it's the Object that requests a delete and
> only for that specific object. A cascade delete can delete a lot of
> objects/records, not just itself.  I guess some delete visitor would
> have to be launched as well on any loaded (in memory) objects.

Indeed.

> 
> Umm... I'll raise this issue in the tiOPF newsgroup as well.

I have the same issue as well, and didn't find a solution other than
manually running a loop over all objects to see which one use the address
type, and refuse to delete if there are some left. I'm assuming that
this is what should happen in the case of an address type.

If you delete a person from a database, then I assume that you really 
want to delete everything that refers to this person as well -> the loop 
would have to delete all objects that refer to the person. 

So the kind of action that must be taken depends on the kind of object.

This is all easily implemented in a RDBMS, usually I don't have to think
of such issues, but one of the major drawbacks of object-oriented 
persistence frameworks IMHO.

Michael.



More information about the Lazarus mailing list