I have a database of customers with each customer having multiple contacts. In my projects i needed a way to make sure each customer always had a primary contact. I ran into a few issues doing this the traditional way.
First off if i set the primary contact field to default to true when a contact was made then i can end up with multiple primary contacts an that defeats the purpose.
If I set the default to false and let the user choose then they may forget to set one in wich case we have no primary contacts.
I needed a way for my system to have a brain of its own so there is no extra work done on the users end.
Heres what i cam up with:
If a contact is made and there are no other primary contacts then the current contact is by default set to be primary.
If there are more then one contacts and the primary contact is deleted, then the first contact on the list is set to be primary. And if a new primary contact is set but we have another user who is the primary contact then His/Her status as primary is removed and the current contact takes over.