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

Joao Morais post at joaomorais.com.br
Tue Sep 9 15:32:23 CEST 2008


Graeme Geldenhuys wrote:
> Now I want to delete a specific AddressType, but that AddressType is
> being used by some Contacts in there address information.
> 
> What's my choices?  How do you handle such a case?
> 
> * What happens if you simply try and delete the AddressType?
> * DB referential integrity might stop the delete, but gives a lovely
> error. If I don't have referential integrity enabled, I have ghost
> address types lying around.
> * Do I have to create some search query to run through all tables looking
> for that AddressType?
> * Must I maybe extend my AddressType table to include some 'Active'
> boolean field. If set to False, it simply hides that record from the
> GUI, but still available in the database?

Always use referential integrity. After transaction, this is the most 
nice RDBMS feature. A 'lovely error message' is far better than ghosts 
in the database, anyway you can choose between query the database before 
try to delete the record (when you have an oo model this is very simple 
to implement within an abstract layer), as well as catch the exception 
and display a real lovely message to the user.

Joao Morais




More information about the Lazarus mailing list